|
Flash Games Studio:
I
contributed a chapter (chapter 7) to the book Flash Games
Studio
published by Friends of ED.
You can find out more information about
the book from the friends
of ed web site.
The chapter I wrote provides an overview on building a platform
game in flash. The game described can be found here: rescue
run
The chapter also covers building a level editor for the platform
game.
Source code:
the source code for the book is available
here.
For some reason my source code isnt online at the moment so
you can get
it here.
A sample chapter by Glen Rhodes is available
here.
Help:
if you have problems with the chapter you can email me at
david@artifactinteractive.com.au
If you find the game is running a bit
slow Ive provided some hints here:
Speed
One of the biggest issues for game development
in Flash is speed. You can set your flash file to run at a
frame rate of 25 frames per second but there is no guarantee
that the flash player will actually run at that speed. The
flash player tries to run at the specified frame rate but
it will often slow down to a lesser frame rate if it is trying
to do too many intensive tasks at once. The result is that
your game may run slowly and a slow scrolling platform game
isn't a lot of fun.
Let's look at some of the things that
slow the flash player down and how you can avoid them.
Large graphics
The Flash player will run slower if it has to manage the movement
of lots of large graphics. If you use large graphics for the
platforms in 'Rescue Run' you will find that the game slows
down. Keep all of the graphics as small as possible.
Lots of movie
clips
It's a general rule that the more movie clips you have moving
around the slower the flash player will run. In 'Rescue Run'
you may notice the game slowing down if you build long and
complex levels. The solution is to have lots of short levels
instead of a few long levels. You may also consider removing
the background scrolling mountains, as this is not critical
to the game and may slow the game engine down if you also
have complex levels with large graphics.
Transparency
and gradients
The flash player has to work harder to render graphics with
transparency settings and gradients. Wherever possible avoid
using graphics with alpha settings or graphics that contain
large gradient fills.
Complex vector
graphics
Even though flash is a vector based program it can some times
slow down slightly when rendering complex vector graphics,
especially graphics with lots of small gradient fills. You
will sometimes find that the flash player performs faster
if you use a bitmap graphic in the place of a complex vector
graphic. For example, if you create a complex vector background
graphic to replace the mountains in 'Rescue Run' you may find
that the game slows down. The solution is to export your vector
background graphic as a png image and then import this png
image back into flash and use that instead of the vector graphic.
High Quality
The flash player will run faster if you set the publish settings
to low quality. You may not like low quality because your
vector graphics and text will look ugly and jagged. However
try running 'Rescue Run' at low quality. The player and text
look terrible, but the rest of the game looks much the same.
This is because most of the game elements are bitmap graphics
and at low quality bitmap graphics appear almost the same
as at higher settings. If you build a game that uses only
bitmap graphics then you may find that it looks good enough
to run the game at low quality. The ugly text that you find
at low quality can be resolved by changing the text font to
a system font such as _sans.
Coding
The complexity and style of coding can affect the speed of
a flash game. The code in 'Rescue Run' has been written to
ensure that the game runs as fast as possible while also being
easy to adapt and understand. An example of coding that has
been written in a specific way to speed the game up is the
platform collision detection. We check for a collision between
the platforms movie clip instead of testing for a collision
against each and every individual platform. This is less code
for the flash player to perform and hence runs faster.
One coding trick that can sometimes speed up flash files is
to change code that is repeated frequently back to flash 4
style syntax. Flash 4 style syntax actually runs slightly
faster in the flash 5 player than the equivalent flash 5 syntax.
So sometimes you will notice an improvement if you go back
to using tell target to control movie clips, set Property
to set properties and slash notation instead of dot notation.
However you should be aware that Macromedia have said that
the flash 4 syntax is depreciated and may not be supported
in future versions of the flash player - so only use flash
4 syntax if you really need to try and find every little extra
speed boost.
Full Screen
Even though flash movies can scale to fill the browser that
doesn't mean you should set your games to 100%. The larger
the flash game is the slower it will run. So keep your games
as small as possible to keep them running at an optimum speed.
The above list shouldn't been seen as a set of rules but rather
guidelines that will hopefully give you a start on how to
modify your game if it isn't running as fast as you would
like.
You should also be aware that there
are some things that may effect the speed of game that you
cant control, such as the speed of the users computer and
if the user has any other browser windows open. In this case
the best you can do is recommend to your users that they close
all other browser windows and provide minimum hardware specifications
for the game. You may also may want to offer users on low
end computers a button that switches the game to low quality
or turns off the games scenery (such as the background mountains
and sky), which should make the game run faster even though
it may not look quite as nice.
link:
some more advanced
coding techniques for speed optimization
|