A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11337 Flash Movies | 1 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Bugra Ozden
» Title: Skatalog v9 - product catalog
» Description: Create your product catalog easly and publish on your website or Create your image gallery, documents list, portfolio. Fully XML Driven
» More by Bugra Ozden


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 5828 Flash Sites | 0 New Flash Links
What's New | Top 100 Flash Site

Featured Site

» Posted in the Flash Kit Links section
» Title: Creative DW Image Show PRO
» Description: Creative DW Image Show PRO is a Dreamweaver extension which enables the user to create multimedia presentations. It combines the features of the popular Creative DW Image Show with the ability to add professional text effects to slides (similar to After Effects). The product is very customizable: the user can choose the duration of the transition effects, the slide motion start and end position, zoom and panning type for both images and texts.


Random Links | Add your own Flash Related Links
Flash Tutorials 1280 Tutorials 7 New Tutorials Added!
What's New | Top100

» Make a Flash Slide Show Screen Saver
» Simple flash making tutorial for thanksgiving
» Create flash banner for website
» Create xml slideshow with free template
» How to Insert a Multilingual Subtitle Into Your Flash Video Studio
» How to Create Cool Halloween Slideshow
» Debugging flash using the Firebug console
» Create Flash Slideshow on Blogger
» FLASH TRICKS IN WEB ADVERTISING: FLASH BANNERS
» Unknown Tag: Title10
Random Tutorial | Add Site

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Games

Categories How to make a flash game with moving platforms
Author: Stephen Harris | Website: http://blog.ninjakiwi.com |

 
Page 2
«prev 1 2

Platforms

Lets get platforms and moving platforms in our game. Create a MovieClip in flash for the platform, making sure that the platform’s registration point is on its top surface. Create as many types and sizes of platform you want. I went with two kinds, but you could easily get away with one type, and just resize each instance to suit the level. Be aware that if you make the platforms too thin, the collision check between it and the base point of the character might fail. Here’s the fun part! Place and resize your platforms to create a simple game level. Decide which platforms will be moving and which will be static. We'll set these actual values in code. For every platform type in the library, set its linkage properties to the Platform class, which you will create next.

Have a look at my Platform.as class. It has some properties and an update method, all of which relate to moving platforms. The Update() method should be called every frame from the PlatformGame class. All it does is reverse the direction if it has moved to one of its limits, and updates the x position based on the current speed and direction. To create a platform with vertical motion, you would need to add properties to set the upper and lower limits of movement. Have fun experimenting with different speeds and types of motion for your platforms.

Note: Static platforms don't require any more properties than the built in MovieClip class, so technically we don't need to make static platforms part of this class. I decided however to have all platforms under the one class so you could chop and change which platforms were moving and which were static without having to mess around too much with different symbol types and linkages in flash. In addition it allows us to add properties to all platforms as our game gets more complex without needing to change anything major. Ultimately it's a preference thing, do what you think will work best for you.

Next we have to set up the platforms in the PlatformGame class. I favour using the Array class for storing objects, it is powerful and easy to use. Add every platform in your level to the array, then set the boolean value movPlat to true for each platform you want to move. Set the limits of movement, the initial direction, and the speed of each platform marked as a moving one. Again you may opt to use a different way to store the data, to allow for multiple levels for instance.

Go back the CheckCollisions function and add a 'for loop' like the one in my PlatformGame.as. You need to perform a MovieClip-to-point hit test between each platform and the player’s base position. If the hit test is true, do three things. Firstly set the touchGround boolean to true, indicating that if falling, the player will stop. Secondly to make the contact clean and without penetration, set the player’s y value equal to the y value of the platform it just collided with. This is why we made the registration point of the character its base, and the platform, its upper surface. If the platform is a moving platform, set the character's myMovPlat reference variable equal to the platform we just collided with. This allows the player’s movement to be affected by the movement of the platform. Also ensure that if the collided platform isn't a moving one, you set the player’s myMovPlat back to null.

check platforms

To make this work, go back to your character class file and add a check in the Character.as Update() function to see if the myMovPlat is not null. If it is not null, modify the x value of the character by the speed and direction of that platform:

check mov plat

Finally, add an UpdateMovingPlats() function to your GameLoop() function, making sure to put it before the call to update the character so the character will stick better to the platform.

game loop

In UpdateMovingPlats() I manually call update on each moving platform. Try running the game again, fixing any obvious bugs, or referring back to my code if you get stuck. You should be able to move the character around the level, jumping from platform to platform.

There are a multitude of cool games you could make with a simple platform game engine, and I wish you the best of luck with it, have fun! View my finished swf file here.

If you found any of this helpful, or end up using some of these concepts in a game you make, let me know, I'd love to see what you create.

Stephen

«prev 1 2

» Level Intermediate

Added: : 2006-09-14
Rating: 7.75 Votes: 21
Hits: 2171
» Author
Flash game programmer
» Download
Download the files used in this tutorial.
Download (106 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs