Skip to content

Instantly share code, notes, and snippets.

@Mr-Coxall
Created May 7, 2018 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mr-Coxall/1062dcfeeea8a052c9acb2bc8fe9af5a to your computer and use it in GitHub Desktop.
Save Mr-Coxall/1062dcfeeea8a052c9acb2bc8fe9af5a to your computer and use it in GitHub Desktop.
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-- Created by: Mr. Coxall
-- Created on: Jan 2018
--
-- This file animates a charact using a spritesheet
-----------------------------------------------------------------------------------------
display.setStatusBar(display.HiddenStatusBar)
centerX = display.contentWidth * .5
centerY = display.contentHeight * .5
local sheetOptionsIdle =
{
width = 587,
height = 707,
numFrames = 10
}
local sheetIdleKnight = graphics.newImageSheet( "./assets/spritesheets/knightIdle.png", sheetOptionsIdle )
local sheetOptionsWalk =
{
width = 587,
height = 707,
numFrames = 10
}
local sheetWalkingKnight = graphics.newImageSheet( "./assets/spritesheets/knightWalking.png", sheetOptionsWalk )
-- sequences table
local sequence_data = {
-- consecutive frames sequence
{
name = "idle",
start = 1,
count = 10,
time = 800,
loopCount = 0,
sheet = sheetIdleKnight
},
{
name = "walk",
start = 1,
count = 10,
time = 800,
loopCount = 0,
sheet = sheetWalkingKnight
}
}
local knight = display.newSprite( sheetIdleKnight, sequence_data )
knight.x = centerX
knight.y = centerY
knight:play()
-- After a short time, swap the sequence to 'seq2' which uses the second image sheet
local function swapSheet()
knight:setSequence( "walk" )
knight:play()
print("walk")
end
timer.performWithDelay( 2000, swapSheet )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment