27.3.15

Point at Pointer 1

Okay, Here's something I haven't done before. Have you ever wanted to figure out how to add a function into a game that points an object at another object? Like if you have a space ship shooter and you want the enemy turrets to point at you and fire, or if you're making a Missile Command style game and you want to have the missile launcher point where your pointer is pointing? Here's how you do it. To start off, create a new Actionscript 3.0 Flash File.

Before you do anything else, make sure that Object Mode is selected at the bottom of the tool box (it's a circle inside of a square).Go into the tool box and press and hold on the Rectangle Tool. A pop-up menu should come. Go down to the Polystar tool at the bottom. In the Tool Settings at the bottom of the menu, click on options. Another pop-up menu should show up. In the Number of Sides field, put 3 (make sure the style field is set to polygon and not star). When you're done click okay.

Now, drag out a triangle onto the field. By default it will be equilateral. Make sure that when you draw it that the top of the Triangle is at a zero degree angle, or pointing perfectly to the right. It might seem logical to have the top pointing up, but it won't work right if we don't point it at zero degrees.

Double-click the triangle and enter inside of it's layers (do not lock the original layer). Create a new layer on top of the original layer and create a new, smaller triangle of a different color than the original. Make sure that it is also pointed at zero degrees, perfectly to the right. It doesn't have to light up perfectly at this time. Now select both triangles and go to the Align menu. Check the box at the the bottom which says "Align to Stage," because we want the symbol's contents to be aligned to the center. Then select the options to align to the middle vertically and horizontally.

Finished? Okay, now exit the shape and go back to the stage. Select the triangle that is pointing to the right, ninety degrees from the Y axis, and select the modify menu and then select Convert to Symbol. Name your new symbol "ThreeSided" with no spaces. Make sure that the registration for the symbol, the symbol's rotation point, is in the exact middle of the shape so that it rotates around its center. Finish making the symbol, then go to your Library panel. Select ThreeSided from the Library and drag it out onto the stage. Click on the object and go to the properties panel.

In the properties panel there is a field called "instance name." Click in this field and type in the name "triangle." Now you have an instance of the ThreeSided class named triangle.

No comments:

Post a Comment