During these days I am playing a bit with FlashPunk and I want to share with you a couple of examples.
We are going to build a simple platform game.
Getting the required software
While most developers use Flash Builder or FlashDevelop, I will use Flash Professional CS5.5, so the first thing you should do is getting a copy of it. You can get a fully functional 30 days trial at this page.
Then, download the latest release of FlashPunk from this page, and you are ready to go.
Preparing the worspace
All in all, FlashPunk is just an AS3 library, and although it has been developed for being used outside the Flash IDE, you just have to copy the net
foder into your project folder and you are ready to go.
Hello FlashPunk
At this time in your main class (I called mine punk
), enter this code:
1 2 3 4 5 6 7 8 9 | package { import net.flashpunk.Engine; import net.flashpunk.FP; public class punk extends Engine { public function punk() { super(640,480,60,false); } } } |
I said FlashPunk has been developed for being used outside the Flash IDE, and that’s it… we haven’t Sprites or Movieclips, but the class extends Engine
FlashPunk’s class.
This line
6 | super(640,480,60,false); |
Calls the constructor of the extended class, that is Engine
constructor, with these arguments:
width: the width of your game in pixels
height: the height of your game in pixels
frameRate: the game framerate, in frames per second (default: 60)
fixed: true if a fixed-framerate should be used, false (default) otherwise.
Test the movie and you will see a dark background color, no matter the Stage color.
Your FlashPunk project works!
Adding some walls
When it’s time to add graphics to our FlashPunk games, we have to draw them with our preferred paint software. Using Photoshop, I made a 32×32 pixels square and called saved it as wall.png
in a newly created assets
folder in the same level of net
(the one which contains FlashPunk library).
Then change punk.as
this way:
No comments:
Post a Comment