Categories
Featured jobs
» More ActionScript, Flash and Flex jobs.
» Advertise a job for free
Our network
Advertisement

 »  Home  »  Tutorials  »  Flash  »  Beginner  »  Creating a Floor, Walls, and Platforms for Games with Flash

Creating a Floor, Walls, and Platforms for Games with Flash

By Sundeep Gottipati | Published 12/31/2006 | Beginner | Rating:
Sundeep Gottipati
Intermediate flash user, with 1 year of experience with actionscript. 

View all articles by Sundeep Gottipati
Creating a Floor, Walls, and Platforms for Games with Flash
First, create a new file. Draw a circle, and double-click it so that the circle and the outline will be selected. Hit F8, which will pop up a window with some options on converting your shape to a symbol. Make sure that the "Movie Clip" button is selected. Options below are unnecessary so you don't have to do anything to them.

For the "name" text box near the top, the default name is Symbol 1, and you don't need to change that. Click "OK", and now your circle is a symbol. Near the properties window (the window located by default below your stage), click the text box called instance name. Name it "ball".

Now, create a big rectangle near the bottom. Convert it into a symbol just as you did with the circle, and in the properties box, type "ground". Now, go to the drop down menu at the top of the screen and click on "window". Go down to "actions" and click it. Now somewhere to the right of the stage, a windows named actions should have popped up. Then click Frame 1 in the timeline and in the actions panel, type "stop;". This just tells flash to stop at the frame unless told otherwise.

Now, making sure you have selected the ball (by clicking on it), copy and paste this actionscript into the actions panel. The actionscript will be explained after.

onClipEvent (enterFrame) {
      this._y++;
}


This tells Flash to move the ball by lowering the y axis of the ball."onClipEvent (enterFrame)" just means that the actionscript (in the curly brackets) should be in effect when the frame is loaded. The script in between the curly brackets (this._y++;) is shown as follows: "this" means the ball, because the above actionscript is for the ball, _y means the y axis, and "++" is the same thing as "= this._y + 1", so the ball is moving one pixel down at the rate of your fps (frames per second). If you run your the movie, the ball will go down, but will fall through the ground. Now to stop this, the ground must act as an opposing force. Copy and paste this:

onClipEvent (enterFrame) {
    if (this.hitTest(_root.ball)) {
        this._y-- ;
    }
}


This has the same framework as the actionscript in the ball. The "if" operator tells Flash to only enter the actionscript in the curly brackets when the parameters (the stuff in the parenthesis are true). this.hitTest(_root.ball)) is asking flash to continuosly check if the ground(this), is hitting the ball. this._y-- is the opposing force of this._y++, so when the ball hits the ground the ball moves 1 pixel down and 1 pixel up creating a non-moving effect. A very important thing to note: the y axis is "reversed", because the x axis is in the left hand corner of the stage.

Hopefully this tutorial will help people who have just started using flash and have an interest in creating small games.

How would you rate the quality of this article?
1 2 3 4 5
Poor Excellent

Verification:
Enter the security code shown below:
img


Add comment

Spread The Word / Bookmark this content

Clesto Digg it! Reddit Furl del.icio.us Spurl Yahoo!

Comments
  • Comment #1 (Posted by Valosa - nirinth at yahoo.com)
    Rating
    This tut has an error. I followed your instuctions and found it did not work. I fixed the error by replacing "this" line 3 with the "_root.ball" Please update.
     
  • Comment #2 (Posted by Ashwini Solanki)
    Rating
    There is an error in this tutorial it will be corected by by using "_root.ball" instaed of 'this" in line number 3
     
Submit Comment



Search Entire Site
Add to Google
Advertisements
Article Options
Latest New Articles
Set up a simple IIS Server for Flash
by Peter McBride

Day 1 at FITC Toronto 2008
by Anthony Pace

Simple reflection effect with AS2
by Jean André Mas

ActionScript.org Meets Josh Tynjala (aka dr_zeus)
by ActionScript.org Staff

Rapidly Create Online Flash Movies to Help Users Market, Sell and Support Software and Hardware
by Sabrina F

mailing list
Enter your email address:
mailing list
Subscribe Unsubscribe
© 2000-2007 actionscript.org! All Rights Reserved.
Read our Privacy Statement and Terms of Use...
Our dedicated server is hosted and managed by WebScorpion Webhosting.