main game loop:
[lua]local function playSequence(plyr, seq)
–plyr:pause()
–timer.performWithDelay( 33, function() plyr:prepare( seq ); plyr:play() end )
plyr:setSequence(seq)
plyr:play()
end
–PLAYER EVENTS
local function playerAnimationEvent( event )
if event.phase == “ended” then
print(“sequence : “…event.target.sequence…” : ended.”)
if event.target == player.left then
playSequence(event.target, “lrdy”)
else
playSequence(event.target, “rrdy”)
end
end
end
–RUNTIME EVENTS
local function screenTouched(event)
local eventY, eventX, startY, startX = event.y - offsetY, event.x - offsetX, event.yStart - offsetY, event.xStart - offsetX
if event.phase == “began” then
if eventX >= halfW then
if eventY >= halfH then
touch.right.low = true
else
touch.right.high = true
end
else
if eventY >= halfH then
touch.left.low = true
else
touch.left.high = true
end
end
determineAction()
elseif event.phase == “ended” then
if eventX >= halfW then
if eventY >= halfH then
touch.right.low = false
print (“Jab Right Low”)
playSequence(player.right, “rjl”)
else
touch.right.high = false
if startY >= halfH and startX >= halfW then
print (“Right UpperCut”)
touch.right.low = false
playSequence(player.right, “rju”)
else
print (“Right Jab High”)
playSequence(player.right, “rjh”)
end
end
else
if eventY >= halfH then
touch.left.low = false
print(“Jab Left Low”)
playSequence(player.left, “ljl”)
else
touch.left.high = false
if startY >= halfH and startX <= halfW then
print (“Left UpperCut”)
touch.left.low = false
–playSequence(player.left, “lju”)
player.left:setSequence(“lju”)
player.left:play()
else
print( “left Jab High” )
playSequence(player.left, “ljh”)
end
end
end
determineAction()
end
end[/lua]
player.left and player.right are the two sprites returned from the spriteLoader class:
[lua]local spriteLoader = {}
spriteLoader.loadPlayerAnimations = function()
local player_left_set, player_right_set
local ljh_file = require(“spriteData.player_ljh@”…scale…“x”)
local ljh_data = { spriteSheetFrames = ljh_file.getSpriteSheetData().frames }
local ljh_sheet = graphics.newImageSheet( “images/fight/player/player_ljh@”…scale…“x.png”, ljh_data )
local ljl_file = require(“spriteData.player_ljl@”…scale…“x”)
local ljl_data = { spriteSheetFrames = ljl_file.getSpriteSheetData().frames }
local ljl_sheet = graphics.newImageSheet( “images/fight/player/player_ljl@”…scale…“x.png”, ljl_data )
local lrdy_file = require(“spriteData.player_lrdy@”…scale…“x”)
local lrdy_data = { spriteSheetFrames = lrdy_file.getSpriteSheetData().frames }
local lrdy_sheet = graphics.newImageSheet( “images/fight/player/player_lrdy@”…scale…“x.png”, lrdy_data )
local lju_file = require(“spriteData.player_lju@”…scale…“x”)
local lju_data = { spriteSheetFrames = lju_file.getSpriteSheetData().frames }
local lju_sheet = graphics.newImageSheet( “images/fight/player/player_lju@”…scale…“x.png”, lju_data )
local player_left_sequence =
{
{ name = “lrdy”, sheet = lrdy_sheet, frames = { 1, 2, 3, 4, 5, 6 }, time = 1000, loopCount = 0 },
{ name = “ljh”, sheet = ljh_sheet, frames = { 1, 2, 3, 4, 5, 6, 1}, time = 1000, loopCount = 1 },
{ name = “ljl”, sheet = ljl_sheet, frames = { 1, 2, 3, 4, 5, 6, 7, 1 }, time = 1000, loopCount = 1 },
{ name = “lju”, sheet = lju_sheet, frames = { 1, 2, 3, 4, 5, 6, 1 }, time = 1000, loopCount = 1 },
}
– sprite.add( player_left_set, “ljh”, 1,7, 1000, 1 )
– sprite.add( player_left_set, “ljl”, 8,8, 1000, 1 )
– sprite.add( player_left_set, “lju”, 16,7, 1000, 1 )
– sprite.add( player_left_set, “lrdy”, 23,6, 1000, 0 )
local rjh_file = require(“spriteData.player_rjh@”…scale…“x”)
local rjh_data = { spriteSheetFrames = rjh_file.getSpriteSheetData().frames }
local rjh_sheet = graphics.newImageSheet( “images/fight/player/player_rjh@”…scale…“x.png”, rjh_data )
local rjl_file = require(“spriteData.player_rjl@”…scale…“x”)
local rjl_data = { spriteSheetFrames = rjl_file.getSpriteSheetData().frames }
local rjl_sheet = graphics.newImageSheet( “images/fight/player/player_rjl@”…scale…“x.png”, rjl_data )
local rju_file = require(“spriteData.player_rju@”…scale…“x”)
local rju_data = { spriteSheetFrames = rju_file.getSpriteSheetData().frames }
local rju_sheet = graphics.newImageSheet( “images/fight/player/player_rju@”…scale…“x.png”, rju_data )
local rrdy_file = require(“spriteData.player_rrdy@”…scale…“x”)
local rrdy_data = rrdy_file.getSpriteSheetData()
local rrdy_sheet = graphics.newImageSheet( “images/fight/player/player_rrdy@”…scale…“x.png”, rrdy_data )
local player_right_sequence =
{
{ sheet = rjh_sheet, name = “rjh”, frames = { 1, 2, 3, 4, 5, 6, 1}, time = 1000, loopCount = 1 },
{ sheet = rjl_sheet, name = “rjl”, frames = { 1, 2, 3, 4, 5, 6, 7, 1 }, time = 1000, loopCount = 1 },
{ sheet = rju_sheet, name = “rju”, frames = { 1, 2, 3, 4, 5, 6, 1 }, time = 1000, loopCount = 1 },
{ sheet = rrdy_sheet, name = “rrdy”, frames = { 1, 2, 3, 4, 5, 6 }, time = 1000, loopCount = 0 },
}
– sprite.add( player_right_set, “rjh”, 1,7, 1000, 1 )
– sprite.add( player_right_set, “rjl”, 8,8, 1000, 1 )
– sprite.add( player_right_set, “rju”, 16,7, 1000, 1 )
– sprite.add( player_right_set, “rrdy”, 23,6, 1000, 0 )
local player_left = display.newSprite( lrdy_sheet, player_left_sequence )
local player_right = display.newSprite( rjh_sheet, player_right_sequence )
local s = 1/scale
player_left:scale( s,s )
player_right:scale( s,s )
return player_left, player_right
end
return spriteLoader[/lua]
Here are the sheet data files. You can see on line 62, I am loading the file a bit differently. I tried loading them both ways (using texturepacker’s default output, or creating a new sprite API sequence data table).
The following is using the new sequence data table format.
[lua]local SpriteSheet = {}
SpriteSheet.getSpriteSheetData = function ()
return {
frames = {
{
x = 2,
y = 2,
width = 518,
height = 536,
sourceWidth = 894,
sourceHeight = 764,
sourceX = 232,
sourceY = 193
},
{
x = 2,
y = 2,
width = 518,
height = 536,
sourceWidth = 894,
sourceHeight = 764,
sourceX = 232,
sourceY = 195
},
{
x = 2,
y = 2,
width = 518,
height = 536,
sourceWidth = 894,
sourceHeight = 764,
sourceX = 232,
sourceY = 197
},
{
x = 2,
y = 2,
width = 518,
height = 536,
sourceWidth = 894,
sourceHeight = 764,
sourceX = 232,
sourceY = 199
},
{
x = 2,
y = 2,
width = 518,
height = 536,
sourceWidth = 894,
sourceHeight = 764,
sourceX = 232,
sourceY = 197
},
{
x = 2,
y = 2,
width = 518,
height = 536,
sourceWidth = 894,
sourceHeight = 764,
sourceX = 232,
sourceY = 196
},
– frames = {
– {
– spriteColorRect = { x = 234, y = 195, width = 518, height = 536 },
– textureRect = { x = 2, y = 2, width = 518, height = 536 },
– spriteSourceSize = { width = 894, height = 764 },
– spriteTrimmed = true,
– textureRotated = false
– },
– {
– spriteColorRect = { x = 234, y = 197, width = 518, height = 536 },
– textureRect = { x = 2, y = 2, width = 518, height = 536 },
– spriteSourceSize = { width = 894, height = 764 },
– spriteTrimmed = true,
– textureRotated = false
– },
– {
– spriteColorRect = { x = 234, y = 199, width = 518, height = 536 },
– textureRect = { x = 2, y = 2, width = 518, height = 536 },
– spriteSourceSize = { width = 894, height = 764 },
– spriteTrimmed = true,
– textureRotated = false
– },
– {
– spriteColorRect = { x = 234, y = 201, width = 518, height = 536 },
– textureRect = { x = 2, y = 2, width = 518, height = 536 },
– spriteSourceSize = { width = 894, height = 764 },
– spriteTrimmed = true,
– textureRotated = false
– },
– {
– spriteColorRect = { x = 234, y = 199, width = 518, height = 536 },
– textureRect = { x = 2, y = 2, width = 518, height = 536 },
– spriteSourceSize = { width = 894, height = 764 },
– spriteTrimmed = true,
– textureRotated = false
– },
– {
– spriteColorRect = { x = 234, y = 198, width = 518, height = 536 },
– textureRect = { x = 2, y = 2, width = 518, height = 536 },
– spriteSourceSize = { width = 894, height = 764 },
– spriteTrimmed = true,
– textureRotated = false
– },
– }
}
}
end
return SpriteSheet[/lua]
Now using the old Texturepacker format. (this is the format used for all the imageSheets except for the ‘rrdy’ on line 62.
[lua]local SpriteSheet = {}
SpriteSheet.getSpriteSheetData = function ()
return {
frames = {
{
name = “Rup_frame_1@4x.png”,
spriteColorRect = { x = 213, y = 258, width = 512, height = 506 },
textureRect = { x = 2, y = 542, width = 512, height = 506 },
spriteSourceSize = { width = 894, height = 764 },
spriteTrimmed = true,
textureRotated = false
},
{
name = “Rup_frame_2@4x.png”,
spriteColorRect = { x = 11, y = 406, width = 644, height = 358 },
textureRect = { x = 2, y = 1534, width = 644, height = 358 },
spriteSourceSize = { width = 894, height = 764 },
spriteTrimmed = true,
textureRotated = false
},
{
name = “Rup_frame_3@4x.png”,
spriteColorRect = { x = 2, y = 282, width = 584, height = 482 },
textureRect = { x = 2, y = 1050, width = 584, height = 482 },
spriteSourceSize = { width = 894, height = 764 },
spriteTrimmed = true,
textureRotated = false
},
{
name = “Rup_frame_4@4x.png”,
spriteColorRect = { x = 11, y = 169, width = 456, height = 538 },
textureRect = { x = 2, y = 2, width = 456, height = 538 },
spriteSourceSize = { width = 894, height = 764 },
spriteTrimmed = true,
textureRotated = false
},
{
name = “Rup_frame_5@4x.png”,
spriteColorRect = { x = 20, y = 15, width = 322, height = 358 },
textureRect = { x = 516, y = 474, width = 322, height = 358 },
spriteSourceSize = { width = 894, height = 764 },
spriteTrimmed = true,
textureRotated = false
},
{
name = “Rup_frame_6@4x.png”,
spriteColorRect = { x = 159, y = 153, width = 440, height = 470 },
textureRect = { x = 460, y = 2, width = 440, height = 470 },
spriteSourceSize = { width = 894, height = 764 },
spriteTrimmed = true,
textureRotated = false
},
}
}
end
return SpriteSheet[/lua]
Let me know if you need more code or resource files. I can zip them up and send them wherever.
Thanks for looking into this.
Regards,
Brian [import]uid: 158289 topic_id: 29774 reply_id: 119654[/import]