Created
May 8, 2018 01:21
-
-
Save Mr-Coxall/69d5d3cedf2aa7042d5aa725ba509f23 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 playerBullets = {} -- Table that holds the players Bullets | |
local dPad = display.newImage( "./assets/sprites/d-pad.png" ) | |
dPad.x = 150 | |
dPad.y = display.contentHeight - 200 | |
dPad.alpha = 0.50 | |
dPad.id = "d-pad" | |
local rightArrow = display.newImage( "./assets/sprites/rightArrow.png" ) | |
rightArrow.x = 260 | |
rightArrow.y = display.contentHeight - 200 | |
rightArrow.id = "right arrow" | |
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 = 1000, | |
loopCount = 1, | |
sheet = sheetWalkingKnight | |
} | |
} | |
local knight = display.newSprite( sheetIdleKnight, sequence_data ) | |
knight.x = centerX | |
knight.y = centerY | |
knight:setSequence( "idle" ) | |
knight:play() | |
function rightArrow:touch( event ) | |
if ( event.phase == "ended" ) then | |
-- move the character up | |
transition.moveBy( knight, { | |
x = 150, | |
y = 0, | |
time = 1000 | |
} ) | |
knight:setSequence( "walk" ) | |
knight:play() | |
end | |
return true | |
end | |
-- rest to idle | |
local function resetToIdle (event) | |
if event.phase == "ended" then | |
knight:setSequence("idle") | |
knight:play() | |
end | |
end | |
rightArrow:addEventListener( "touch", rightArrow ) | |
knight:addEventListener("sprite", resetToIdle) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment