sprite multiset animation sequence error

I have this code where I load 5 different sprite sheet images, which were previously just one big sprite sheet image, and I am trying to create a sprite set using the function newSpriteMultiSet(), but I can’t seem to get it to work run :frowning:

Here’s the code by the way:
[blockcode]
local idleData = require(“buchokoy_idle”)
local cryData = require(“buchokoy_cry”)
local runData = require(“buchokoy_run”)
local moveElbowData = require(“buchokoy_move_elbow”)
local moveLegData = require(“buchokoy_move_leg”)

local spriteIdle = sprite.newSpriteSheetFromData( “buchokoy_idle.png”, idleData.getSpriteSheetData() )
local spriteCry = sprite.newSpriteSheetFromData( “buchokoy_cry.png”, cryData.getSpriteSheetData() )
local spriteRun = sprite.newSpriteSheetFromData( “buchokoy_run.png”, runData.getSpriteSheetData() )
local spriteMoveElbow = sprite.newSpriteSheetFromData( “buchokoy_move_elbow.png”, moveElbowData.getSpriteSheetData() )
local spriteMoveLeg = sprite.newSpriteSheetFromData( “buchokoy_move_leg.png”, moveLegData.getSpriteSheetData() )

– SPRITE SETS. ADD THE MULTI SET ON DECIDED THE ORDER OF FRAMES
local BUCHOKOY_SET = sprite.newSpriteMultiSet(
{ sheet = spriteCry, frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 } },
{ sheet = spriteMoveElbow, frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 } },
{ sheet = spriteIdle, frames = { 1, 2 } },
{ sheet = spriteMoveLeg, frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } },
{ sheet = spriteRun, frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } }
)

– ADD THE SPRITE SEQUENCES
sprite.add(BUCHOKOY_SET, “cryStart”, 1, 12, 600, 1)
sprite.add(BUCHOKOY_SET, “cryLoop”, 12, 2, 500, 0)
sprite.add(BUCHOKOY_SET, “elbowLeft”, 14, 8, 320, 1)
sprite.add(BUCHOKOY_SET, “elbowRight”, 22, 8, 320, 1)
sprite.add(BUCHOKOY_SET, “idle”, 30, 1, 100, 0)
sprite.add(BUCHOKOY_SET, “legLeft”, 32, 6, 350, 1)
sprite.add(BUCHOKOY_SET, “legRight”, 38, 6, 350, 1)
sprite.add(BUCHOKOY_SET, “run”, 44, 12, 1200, 0)

– MAIN SPRITE INSTANCE
local BUCHOKOY = sprite.newSprite(BUCHOKOY_SET)
BUCHOKOY:setReferencePoint(display.CenterReferencePoint)
BUCHOKOY.x = 2+170; BUCHOKOY.y = display.contentHeight-85-2
BUCHOKOY:prepare(“idle”)
BUCHOKOY:play()
localGroup:insert(BUCHOKOY)
[/blockcode]

I keep getting an error saying bad argument #1 to 'add' (sprite.ISpriteSet expected, got nil) on the first sprite.add, specifically sprite.add(BUCHOKOY\_SET, "cryStart", 1, 12, 600, 1). Can someone help me with this one? Thanks in advance! :smiley: [import]uid: 35757 topic_id: 11888 reply_id: 311888[/import]

I am having a similar issue - did you ever get this one resolved? [import]uid: 18601 topic_id: 11888 reply_id: 47724[/import]

I think the problem is you need to encase that with another set of curly braces. like so.

-- SPRITE SETS. ADD THE MULTI SET ON DECIDED THE ORDER OF FRAMES local BUCHOKOY\_SET = sprite.newSpriteMultiSet( { { sheet = spriteCry, frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 } }, { sheet = spriteMoveElbow, frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 } }, { sheet = spriteIdle, frames = { 1, 2 } }, { sheet = spriteMoveLeg, frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } }, { sheet = spriteRun, frames = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 } } } ) [import]uid: 78015 topic_id: 11888 reply_id: 61490[/import]

@paul: yes, thats right.

anyone else fighting the problem with multi set animations? it seems always to take a sprite from another sheet at the beginning and end… [import]uid: 90610 topic_id: 11888 reply_id: 64616[/import]

Actually Dingo yes, I’m having exactly this problem.

In the following code I have a timer set up to change from the “Idle” sheet to the “flip” sheet after 3000ms. This works fine.

However, if I change the “flip” sheet for any other sheet in my MultiSprite, (“grab,” “turn” etc) it still plays the flip sheet.

I can’t for the life of me figure out what’s going on.

require "sprite"  
  
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 } },  
 { 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,10,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",1,5,500,1)  
   
local player1 = sprite.newSprite(spriteSet)  
player1.x = display.contentWidth / 2;  
player1.y = display.contentHeight / 2;  
  
player1:prepare("idle")  
player1:play()  
  
local function resetToIdle (event)  
 if event.phase == "end" then  
 player1:prepare("idle")  
 player1:play()  
end  
end  
  
player1:addEventListener("sprite", resetToIdle)  
   
local function change()  
 player1:prepare("turn")  
 player1:play()  
end  
  
Timer1 = timer.performWithDelay(3000,change, 0)   

I’ll try and find some way to upload a *.zip with the project folder to aid troubleshooting.

Thanks [import]uid: 67933 topic_id: 11888 reply_id: 66439[/import]

hi spider,

i gave it up with the multiset story. right now, i splitted the sheets into diff spritesets and dynamically switch the animations.

runs (so far), pretty well. and has the advantage, that much less texture memory is being used. [import]uid: 90610 topic_id: 11888 reply_id: 66459[/import]

Dingo.

I already have seperate spritesheets. How are you switching them dynamically?

The API listing for Multisprites is not in depth enough to make good use of them, which is a pity. I’ve seen several similar issues.

Cheers

Dan [import]uid: 67933 topic_id: 11888 reply_id: 66461[/import]

as soon as you

[lua] local spriteIdle = sprite.newSpriteSheetFromData( “buchokoy_idle.png”, idleData.getSpriteSheetData() )[/lua]

load spriteSheetData, the texture memory goes up. therefore i’ve made a function that accepts a string for the corresponding animation. i have a simple if else switch that loads the corresponding spritesheetdata to the local spritesheetdata var. same with the local spriteset. then i simply call

[lua]char = sprite.newSprite(getSpriteSheet(anim));[/lua]

whereas getSpriteSheet returns the spriteset. [import]uid: 90610 topic_id: 11888 reply_id: 66464[/import]

Hey Dingo.

Thanks for the response.

Your explanation went a little over my head, (I’m still learning). How did you tell your function to accept a string, and how is that string generated, (inside a button listener or on collision for example?)

My player character is a physics object, and I need to be able to swap between spritesheets depending on different conditions, i.e. if a button is pressed, if he collides with a section of geometry, etc.

With the method you describe, would I be able to change the characters spritesheet on the fly, without destroying him and re-creating him each time?

Cheers

Dan [import]uid: 67933 topic_id: 11888 reply_id: 66469[/import]


With the method you describe, would I be able to change the characters spritesheet on the fly, without destroying him and re-creating him each time?

I’ve faced the same problem first. That’s what i did: my player is a displayGroup, that keeps all the properties. and the only child in that displayGroup is my sprite, the real char. so actually, i am recreating the visual appearance every time. this works for my game, i am not sure if it is fast enough for yours?


Your explanation went a little over my head, (I’m still learning). How did you tell your function to accept a string, and how is that string generated, (inside a button listener or on collision for example?)

All i do is, for example after a touch event, call the method changeAnimation(anim) in the player.lua file. you can call that from everywhere you want. [import]uid: 90610 topic_id: 11888 reply_id: 66472[/import]

I don’t think it’d be feasible to recreate the visual appearance each time, as he’ll be changing velocity/rotation etc and that needs to be in realtime.

In the code I’ve posted above, I prepare and play a spritesheet for the character on a timer. That could easily be changed to a touch event/collision etc. How are you swapping spriteSheets in and out in your changeAnimation(anim) method? Are you setting the current sprite to nil, then recreating it with the new sheet?

Sorry to ask so many questions, I’m just a little confused.

Thanks [import]uid: 67933 topic_id: 11888 reply_id: 66475[/import]

Just wanted to add that I myself was never able to get the sprite.newSpriteMultiSet to work either which was disappointing. It basically went 10 frames from one sheet and then 10 from sheet2. It would make the 20 frames but the second 10 were just repeats from sheet 1. I went over and over the code and there was no errors to be found, it just simply didn’t work. There must be something buggy about it. [import]uid: 78015 topic_id: 11888 reply_id: 66483[/import]

Yeah I think maybe I’m flogging a dead horse trying to use multisheets. It doesn’t help that the support/API documentation is so scant.

I wish there was a working example someone could provide, but I can’t see anything. Perhaps someone from Ansca could clarify why we’re all getting the errors/odd behaivour.

Thanks for the response. [import]uid: 67933 topic_id: 11888 reply_id: 66492[/import]