Cover by Michelle M. Fernandez

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Time for action – creating the character

The main character was created with a sprite sheet and needs to be set up to view the animation it provides. Other display images that will make an appearance include a cracked egg when a collision to a physical object has been made.

  1. Create a new local function called createChar().
        local createChar = function()
  2. Create the sprite sheet for the main character.
          local characterSheet = sprite.newSpriteSheet
            ( "charSprite.png",128, 128 )
          local spriteSet = sprite.newSpriteSet(characterSheet, 1, 4)
          sprite.add( spriteSet, "move", 1, 4, 400, 0 )
          charObject = sprite.newSprite( spriteSet )
          charObject:prepare("move")
          charObject:play()
  3. Set the starting position and physical properties for the main character.
     charObject.x ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required