Tuesday, February 5, 2013

Mobile bandwagon

It looks like I have returned to the mobile gaming bandwagon. Not only is the Ludum Dare port basically finished, but I have set my focus on a side-scrolling hack and slash game for handheld devices. Most likely it will be free to play, supported only by ads and sprinkles of virtual goods. Here is an early prototype screenshot...


First I want to get the underlying technology out the way. I license Corona, so that already gets me 99% of the way there. The two blue buttons on the left are for movement, and the right buttons will be for attacking and special abilities. 

Naturally I wanted to test the game with the keyboard in the simulator, but Corona does not support this. Playing just with the mouse in unmanageable because multiple buttons needs to be pressed simultaneously (normally two thumbs on the actual device screen).


My solution was to write a classic DirectInput application in C++ that records all current keys being pressed and saves the results to a file. Then in my game, I simply open and close the file each frame to handle specific key input. It is a complete hack! Yet it works!... And makes testing much easier. My chosen keys are on the number pad, so typing code does not cause the character to react annoyingly.

Secondly, Corona is bundled with a tool called Spriteloq for rasterizing a Flash movie clip SWF. This is great for most art assets, but I want my characters to have smooth paperdoll animation. I revised an algorithm I have written in Flash, that dumps rotation and translation from the transformation matrix of each body part as Lua code. In other words, I only need to import a tiny sprite sheet like this:


And use the dumped code for each body part, such as five frames of the warrior's back arm efficiently written as arrays instead of tables in Lua:

-- x, y, rotation
Anim_Warrior_armb = {
15.4,-31.35,-13.27, -- frame 1
15.35,-31.45,-13.27, -- frame 2
15.35,-31.65,-13.27,
15.35,-31.85,-13.27,
15.35,-32,-13.27,
etc,
}

Instead of monolithic sprite sheets like this:


It would not be feasible on memory constrained devices. I would need a whole new one just for a different weapon, and another at 2.1x the resolution for the HD version.

Contact me for any of this tech. I would post it now, but it really needs to be cleaned up first.

2 comments:

Sam said...

Could you post a snipped of your texture loading code? In order to pack a texture like that you need easy access to individual sections of an image. Usually that's done using an external tool like Texture packer, which exports the image and an xml atlas.

I'm interested in a simpler (super fast) implementation, that would be compatible with all kinds of atlases, so I can use any bone animation tools with minimal effort.

Elliot Pace said...

Wow, that spine tool link looks amazing! I actually use Spriteloq to package sprites from a SWF. It exports a lua file, so Corona actually does all the work in loading the textures.