Created
May 7, 2018 12:55
-
-
Save Mr-Coxall/1062dcfeeea8a052c9acb2bc8fe9af5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----------------------------------------------------------------------------------------- | |
-- | |
-- 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