Figuring Out HaxePunk

Well, I’m trying to learn HaxePunk, which is a HaXe port of FlashPunk, but both are lacking something important. Good overview. Even pouring over the documentation doesn’t give me a good idea of what everything is and how they fit together. I’m able to figure out some things via the tutorials, and so I’m going to try to piece together the workings of FlashPunk and HaxePunk. I’m also going to check out the source, and see if I can’t figure out something from that.

At any rate this gives me something to do while I try to brute force my way into the Diablo III Open Beta. I’m not sure if Blizzard is failing their stress test, or if they’re intentionally using less than their capacity to see what happens when stuff goes wrong.

So, HaxePunk. The basic thing for HaxePunk is the Engine class. When you make a HaxePunk project you make your main class extend the Engine class, and override the Engine class’s methods to add functionality. You give the constructor the details about screen size and frame rate, and it’s basically a sprite on the stage for you Flashers.

You override the init method of the Engine class and that runs once when the program starts. That initializes the game for you. Then there’s update, which updates the active world, and render, which draws everything to the screen, each every frame.

Then there’s HXP, which is a mix of constants and references to important data across the various classes. When you set which world is currently active, you set it through HXP.

The next most important class is World. Your game takes place in one or more World instances. You set a world to the A world contains entities, which are physical objects that do things in the game. Those entities have a graphics property which can be one of several different graphic type classes. An Entity also has an update method you can override, and various methods for collisions and things.

That much I was able to glean from the tutorials and such. But there’s other stuff in there.

The World class has layer variables. I would guess so that you could have multiple layers of background and foreground sprites, without having them collide. Or for doing paralax scrolling. That sort of thing.

The code in the libraries spaghettis a lot, especially due to the HXP class. I think I’ll need to actually try a lot of these elements out to see what they do. For that, I need to set up an experiment game.

*work work work* Well so far I’ve made an area with a tilemap of floor and barrier tiles LoZ style, and a little red box to be the ‘player’, and the camera follows the player, and the player moves in response to the arrow keys. I also put a pair of parallax scrolling textures in the background, and they’re very neat and hypnotic. It’s a couple of repeating textures using the “Backdrop” class; it’s a graphical class made for non-interactive looping background images.

Next I’ve got to set up some collision stuff.

*work work work work work* Alright! I managed to figure out the built-in movement-collision system. Now I need to take a break.

*takes a break* At this point I should probably mention that unlike my other blog entries, this one is being written over the course of several days. I think this is the fourth time I’ve opened it up and started writing. Usually I close it down when I’m done for the day and post it, but instead I’ve just been adding to it as I go.

I’ve got my little test game going now, but another thing I’m doing is commenting on all of the classes. I’ve got a little folder and I’m slowly filling it up with .txt files named after each of the HaxePunk classes. I’m going to try and figure out what each of them does, and piece together the full intent of the HaxePunk/FlashPunk system. I really have no idea why something like this isn’t already in the API or the documentation anywhere, but so far the code itself hasn’t been _too_ difficult to figure out, once I open the source.

One more thing I’ve been able to figure out is that the entire Masks namespace is full of collision masks. Masks is kind of a vague name, but all the masks are used for collision. They get popped into an Entity’s mask property and compared against for collision.

That leaves the last big mystery, the tweens.

*work work work* Okay before I dive into the tweens I decided to dive into the render loop. I wanted to know how the game works on that end. It seems that it has two bitmaps, and it draws to one in the background using copypixels, and then does a page flip to make a buffer. That’s how I was considering making one, so that’s great, saves me the work. The worry/concern/question I have though is this: Is it neccesary to have two drawing surfaces? I would imagine that Flash/NME handle clipping and page buffers in their own rendering. Maybe it is neccesary. I’m not sure.

Anyways it works, so that’s good enough for me right now.

Now let’s see if I can figure out what these tweens are. I know that in animation, a tween consists of the frames between key frames. In particular in Flash animation, tweens are automatically generated animations based on the differences between one vector image and another. They’re kind of infamous for being terrible, though they’re effective. I studied them a bit in college, and I think if you do them right they don’t have to look terrible, but I’m not much of an animator…

Anyways, near as I can tell there are two classes that subclass the Tweener class, world and entity. The Tweener class lets you apply tweens, which are defined in three different namespaces. So, I should be able to apply a tween to an entity or the world, to see what it does.

To have a clearer idea, I’m going to add another entity into the world.

*work work work* I added a test pattern object, I’m going to try putting tweens in there first to see what they do.

… I’ve just tried the Alarm tween. It didn’t seem to do anything, so I went into the code. I think it’s just a glorified timer. You can supply a callback function when the tween is done, so this one just gives you the callback after the timer is up.

Hmm… The AngleTween is definately SUPPOSED to do something, but I’m having trouble making it actually do something. I’m pretty tired now, though, so I’m going to try to sleep.

I’m going to post this as an entry today, around a week after I last updated it. I’ve been too busy on a different project and now I’m going to work on TextWorld for a while, so I want this up for when I decide to work on HaxePunk some more.

Tagged ,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.