Go back to How To Make A Simple Space Shooting Game In Flash
1. Start by creating a new document (CTRL + N, select Flash ActionScript 2.0 Document) and modify the frame rate to 45 fps in the properties pane, this will make the game run nice and smoothly.
You may also want to change the background color of the document into #1E1E1E or R=30, G=30, B=30.
2. Next is to find an image of a spaceship to move, you can draw one yourself or download an image from the internet.
After we have the image of the spaceship, drag and drop it to the document. Select it then hit F8. In a new pop up window, name it as "Spaceship", tick MovieClip, click/set the Registration on the center box and press OK. Now the ship became a MovieClip object, which means it is now going to be animated.
Select the MovieClip and press F9, this will open the action script code editor where you can put in the code that the spaceship will use.
3. Now, we will want to move the spaceship when we press a key.
Enter the code below:
onClipEvent(enterFrame){ if(Key.isDown(Key.LEFT)){ _x -= 6; }else if(Key.isDown(Key.RIGHT)){ _x += 6; } }
onClipEvent(enterFrame){- This code tells that the code inside this function will be executed everytime a frame is entered. In other words, this function gets called every 45fps.
if(Key.isDown(Key.LEFT)){
- This code checks if the left arrow key is being pressed down, if so, then it executes the code inside it._x -= 6;- This simply subtract or decrement 6 pixels of the spacehip's current X axis.
}else if(Key.isDown(Key.RIGHT)){- This line will be used so that if the left arrow key is not pressed down, it will check if the right arrow key is currently being pressed. If so then it will execute the code inside it.
_x += 6;- Now this is the opposite direction, it will add 6 pixels to the spaceship's current X axis.
Below are needed to close the elseif condition tags and the onClipEvent() function tags:
} }
Go back to How To Make A Simple Space Shooting Game In Flash
1 comment:
i played that game,
it is fantastic and thanks for this amazing tips for making game,
now i am going to try.
Facebook App Developer
Post a Comment