Loading presentation...

Present Remotely

Send the link below via email or IM


Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.


Creating a Flash Platformer - part 1

No description

David Atkinson-Beaumont

on 21 November 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Creating a Flash Platformer - part 1

Part 1
Assuming you have a flash project set up with a document class that switches between a main menu, a game level and a game over screen, you can start creating the elements of the platformer
Open the levelOne movie clip and create a rectangle. Use simple colours, this is a placeholder.
Add the following line of code:
This function will be called in the constructor and will be used to get the game ready for the player. To begin with we instantiate the player and place it
Next we will add some key presses
A keypress is an event that the stage needs to be aware of so we add these to the handleAddedToStage function.
stage.focus = stage;
Once you put the code in, nothing may happen unless you click on the mouse to focus the stage. this is a pain so put this line in the handle function
So far your code and game should look like this:
Next ensure your levelOne script resembles this:
private var myPlayer:player;
In order to be able to do this we need a script for our player and a MovieClip (MC). Lets convert our rectangle to an MC called player with an actionscript called player
In levelOne we will add a new function called setUpGame()
Make sure you haven't left the original player movie clip on levelOne
The KeyPresses need their own functions to react to the event. For now lets just put a trace in to check it works
What's a Trace statement?
You also need to import the Keyboard events library
Now we need to start giving the player some functionality
add these variables to the player class
Now lets make the player fall
We'll begin by setting the X and Y speed and establish the fact that the player is not standing on anything and is in the air
If this runs, nothing happens because there is no Y Speed
Lets add in two constants
First the loop:
Name the instance hitAreaBox
Now we need to loop through everything on the stage, check if its a platform and if it is, check to see if the player is standing on it and if they are, set it to the standingOn variable in player
private var inAir:Boolean;
private var speedX:Number;
private var speedY:Number;
private var standingOn:*;
Next we add a new function called updatePlayer()
We will call this function in each game loop, lets add an if statement to make the player fall if he/she is in the air and also add the playerUpdate call to the main game loop.
So far we have this:
public static const GRAVITY:Number = 1;
public static const MAX_SPEED:Number = 10;
What's the difference between a constant and a variable?
Next add this to the playerUpdate function
if (this.speedY < MAX_SPEED){
this.speedY += GRAVITY;
Time to add platforms
Create a new MovieClip called platform, make it a simple rectangle with an actionscript attached.
Now we need to know if the player has hit a platform. To make this simpler, we are going to add an invisible square onto the feet of our player.
Place a few platforms in the levelOne MC
Why is this simpler?
We need the player to know that they have hit something that can be stood on
Add this function to player:
Add a palm tree to your platform
How does this affect your functionality?
This happens because of the hit box that flash uses to detect collisions
Then, instead of a trace statement, have this line:
What happens next may confuse and surprise you
How do you sort it out?
That's it for now
Next time we will add movement and jumping
Full transcript