Corona – Sprites Simple Game

Here’s an example that builds off the last post about creating an explosion sprite. In this example we’ll create some alien sprites that move down the screen. When touched these aliens explode.

The explosion sprite sheet and code was taken from this post: Corona – Sprite Explosion.

For this example I used this sprite sheet for the alien: 

Continue reading Corona – Sprites Simple Game

Corona – Sprite Explosions

Sprites

Often you’ll want to create an animated object on the screen, have it play through an animated sequence then remove itself from the screen. In this example I’ll created an animated explosion. The explosion appears when you tap the screen, then removes itself once the sequence of frames is complete.

Sprite Sheet

Creating the sprite sheet. I used the explosion generator here: http://www.nuvorm.nl/?p=1. You’ll need to have the Flash player installed to use this. It generates a sequence of frames in a wide image. The iPhone 3 does not support images larger than 1024 and the 4 supports maximum dimensions of 2048. The explosion image generated from nuvorm.nl was 3999px wide. I had to take this into Photoshop and arrange the image into multiple rows.

I calculated the size of each frame by counting the frames and dividing by the width. Turns out I had 43 frames. This meant each frame 93 px wide. The original image was 100 pixels tall. I sized the image 400 px tall. Then I moved the rows of 10 frames to create a new image 10 frames wide by 4 frames tall. When I was done I had created the image below:

Note the last few frames didn’t have much in them so I dropped the last three frames and made the sequence 40 frames long.

Continue reading Corona – Sprite Explosions

Corona – Accelerometer

Accelerometer

The Accelerometer is built into all IOS and other handheld devices, it detects motion of the device, tilting or shaking. Corona handles this with the Accelerometer event.

Remote Test

The accelerometer is difficult to test with, since the Accelerometer events are not available in the simulator. This means that you need to build your project each time you want to test. Which tedious and slow. There’s a solution!

There are several apps that can be used to send accelerometer and other events from a real device to the simulator.

All of these apps are very similar. You install them on a device: iPhone, iPad, iPod Touch etc. Launch and Configure the app. Set up your Corona project to receive data from the device. This consists of adding a few lines of code to your main.lua file.

Continue reading Corona – Accelerometer

Corona – Physics

Corona Physics

Corona incorporates the Box2d physics engine. The physics engine allow you create objects that move and interact like real physical objects. The engine works in flat 2d space.

The Corona implementation of Box2d is simple and intuitive to use. making it incredibly easy to add physics based motion to any project.

Starting physics

To work with physics you’ll to load the physics library and start the physics engine.

Start the physics engine by loading it with:

local physics = require( "physics" )

From here you’ll create physics objects and control the general physics environment through the variable physics defined in the line of code above.

Then start physics with:

physics.start()

Note: You must call start physics, with the line above doing anything else with physics.

Continue reading Corona – Physics