quick question about sprite sheets

I’m using a spriteMultiSet for my player character and have several sprite sheets in the set.

I’ve got as far as changing one sprite sheet for another when conditions are met, i.e;

if conditions == true then  
 player1:prepare("playerTurn")  
 player1:play()  
end  

But I have a few questions.

Firstly, once the spritesheet “playerTurn” has completed, I’d like him to revert back to his “idle” spriteSheet. Reading the API documentation, there doesn’t seem to be a easy way to do this, such as;

if playerTurn.end == true then
player1:prepare(“Idle”)
player1:play()
end

The only way I can think to accomplish this is to set up a trigger/switch which flips from one sheet to the other depending on the frame currently being displayed. That’s fine, but I wanted to see if anyone knew of a simpler way before I start putting my final code together, (I don’t want to have to do it twice).

Secondly, does a spriteSheet occupy space in memory every time it is called, or just the first time?

Sorry if my questions aren’t very clear, (very tired after work) I can provide further examples of code/explanation if needed.

Thanks

Dan [import]uid: 67933 topic_id: 17441 reply_id: 317441[/import]

There is an onComplete listener for sprites;

[lua]local function test (event)
if event.phase == “end” then
print “test”
end
end

yourSprite:addEventListener(“sprite”, test)[/lua]

For memory, it will only use the memory once and not multiple times.

Peach :slight_smile: [import]uid: 52491 topic_id: 17441 reply_id: 66187[/import]

Morning Peach,

I clocked the event listener but in my zombified state didn’t twig that it had the ened state.

Thanks for clearing that up, that’s made my day!

Dan [import]uid: 67933 topic_id: 17441 reply_id: 66199[/import]

Ok, so I thought I had it working when I specified for my player to run through the “flip” spritesheet and onComplete revert back to the “idle” sheet. That works perfectly.

However, If I change it from the “flip” sheet to any other sheet, (“grab,” “turn” etc) then it either still plays through the flip sheet or gives me some weird stuttering glitch with blank frames.

Here’s my full code, (sadly it’s not drag and drop because of the sprite sheets)

[code]

physics = require(“physics”)
physics.start()
physics.setGravity(0,9.8) – change gravity to control the jump curve.

require “sprite”
display.setStatusBar( display.HiddenStatusBar )

_H = display.contentHeight;
_W = display.contentWidth;

canJump = false

local idleSheet = sprite.newSpriteSheet( “idle.png”, 30,30)
local flipSheet = sprite.newSpriteSheet( “flipsheet.png”, 30,30)
local grabSheet = sprite.newSpriteSheet( “grabsheet.png”, 30,30)
local turnSheet = sprite.newSpriteSheet( “turnsheet.png”, 30,30)
local pumpSheet = sprite.newSpriteSheet( “pumpsheet.png”, 30,30)

local spriteSet = sprite.newSpriteMultiSet(
{
{ sheet = idleSheet, frames = {1}},
{ sheet = flipSheet, frames = { 1,2,3,4,5,6,7,8,9,10 } },
{ sheet = grabSheet, frames = { 1,2,3,4,5,6,7,8,9,10 } },
{ sheet = turnSheet, frames = { 1,2,3,4,5,6,7,8,9 } },
{ sheet = pumpSheet, frames = { 1,2,3,4,5 } },
})

sprite.add(spriteSet,“idle”,1,1,1,1)
sprite.add(spriteSet,“flip”,1,9,500,1) --sprite.add( spriteSet, sequenceName, startFrame, frameCount, time, [loopParam] )
sprite.add(spriteSet,“grab”,1,9,500,1)
sprite.add(spriteSet,“turn”,1,9,500,1)
sprite.add(spriteSet,“pump”,5,5,500,1)

local player1 = sprite.newSprite(spriteSet)
player1.x = _W / 2;
player1.y = _H / 2;
physics.addBody(player1, {density = 1.0, friction = 0, bounce = 0.2})
player1.myName = “player1”

local function test (event)
if event.phase == “end” then
player1:prepare(“idle”)
player1:play()
end
end

player1:addEventListener(“sprite”, test)

player1:prepare(“idle”)
player1:play()

local ground = display.newRect(0,0,_W, 5)
ground.x = _W / 2
ground.y = _H - 100
ground:setFillColor(0,255,0)
physics.addBody(ground, “static”, {density = 0, friction = 0, bounce = 0})
ground.myName = “ground”

local function jumpPlayer1 (event)
if canJump == true then
player1:applyLinearImpulse( 0, -5, player1.x, player1.y )

player1:prepare(“flip”)
player1:play()
end
canJump = false
end

local blueButton = display.newCircle (0, 0, 30, 30)
blueButton.x = _W / 2
blueButton.y = _H - blueButton.contentHeight / 2 - 10
blueButton:setFillColor(0, 0, 255)
blueButton.alpha = .75

blueButton:addEventListener (“touch”, jumpPlayer1)

function onLocalCollision( self, event )
if ( event.phase == “began” ) then
if (self.myName == “player1” and event.other.myName == “ground”) then
canJump = true
end
end

if ( event.phase == “ended” ) then
canJump = false
end
end
player1.collision = onLocalCollision
player1:addEventListener( “collision”, player1 )

Thanks. [import]uid: 67933 topic_id: 17441 reply_id: 66212[/import]

At that length and not being drag and drop especially you’d be better suited to http://www.anscamobile.com/corona/support/ probably.

Not being able to test makes things a bit tricky :wink: [import]uid: 52491 topic_id: 17441 reply_id: 66216[/import]

Hey peach.

Thanks for the link, but there’s no way I can afford to shell out any additional cost at the moment.

I totally appreciate that it’s asking a lot for people to take so much time over my issue.

It’s the code between lines 13 and 32 which seems to be causing me hassle.

The function to change which spritesheet is prepared/run is between lines 63 and 71.

The exact issue is that if I change line 67 to:
player1:prepare(“grab”) or
player1:prepare(“turn”)

It still plays through the “flip” animation.

I’d love to be in a position to pay for immediate support, but my current situation means I’ll have to wait and see if anyone can take the time to look through. I’ll happily email the spritesheets/project folder to anyone willing to take a look, I’m not precious about my code, and it’s a pretty simple task I’m trying to achieve.

Thanks again.

Dan

[import]uid: 67933 topic_id: 17441 reply_id: 66225[/import]

I can understand that.

Maybe upload it somewhere and put a download link? Someone might be able to assist.

Else, hopefully someone will request an email.

Peach :slight_smile: [import]uid: 52491 topic_id: 17441 reply_id: 66385[/import]