Issue setting currentFrame after preparing sequence

Ok so I am having an issue where after I set a sequence with prepare and play, I am no longer able to set currentFrame to a frame that is not in that sequence.

I want to set currentFrame to 12, but its not allowing me to

[lua]local spriteSheet = sprite.newSpriteSheetFromData(“sprites/spriteSheet.png”,sheet.getSpriteSheetData() )
local set = sprite.newSpriteSet(spriteSheet,12,12)
sprite.add(set,“extend”,1,11,150,-1)[/lua] [import]uid: 9484 topic_id: 18778 reply_id: 318778[/import]

Is there a reason you’re not doing 1,12 on line 2?

Peach [import]uid: 52491 topic_id: 18778 reply_id: 72351[/import]

Yea, its just b/c I have other graphics on the same sprite sheet. The start of this particular sequence starts at frame 12 of the sprite sheet and has 12 frames in the sequence. [import]uid: 9484 topic_id: 18778 reply_id: 72353[/import]

Looking at the code it’s not the “standard” way of doing sprites; are you using spriteloq or a third party tool? [import]uid: 52491 topic_id: 18778 reply_id: 72369[/import]

spriteSet = sprite.newSpriteSet(spriteSheet, startFrame, frameCount)

startFrame is the index number of the first frame of the sprite, using the index defined in newSpriteSheet() above, and frameCount is the total number of frames in the set.

Anyways my issue is not with that, it is with trying to set currentFrame.

For example:
[lua]local sprite = require(“sprite”)
local sheet = require(“spriteSheet”)

local spriteSheet = sprite.newSpriteSheetFromData(“sprites/spriteSheet.png”,sheet.getSpriteSheetData() )
local set = sprite.newSpriteSet(spriteSheet,12,12)
sprite.add(set,“extend”,1,11,150,-1)
local object = sprite.newSprite(set)

object.currentFrame = 12 – works here

object:prepare(“extend”)
object:play()

object.currentFrame = 12 – doesnt not work [/lua] [import]uid: 9484 topic_id: 18778 reply_id: 72420[/import]

That should work fine - the problem is that you’re calling it at the same time as you start playing the sprite, so the sprite will play past it and at that speed you may not even be able to see it.

You need to pause the sheet then set the frame and it will be visible :slight_smile:

Peach [import]uid: 52491 topic_id: 18778 reply_id: 72583[/import]

Hi,
I have the same problem.
currentFrame is readOnly in fact.
Is there a way to set this property?
Or is there a solution to put a sequence at a certain frame?
Because I need to put my sequence on a specific frame during collision.
Or maybe sprite is not the solution for “discret” frame?
Thanks for your time :slight_smile: (and sorry for my english)
Olivier [import]uid: 160159 topic_id: 18778 reply_id: 115709[/import]

Which sprite API are you using? The brand new one or the slightly older one which lancer was using above?

If the slightly older one then obj.currentFrame = 5 DOES work, I assure you.

Peach :slight_smile: [import]uid: 52491 topic_id: 18778 reply_id: 115788[/import]

Really? I thought one had to use sprite:setFrame(x)… [import]uid: 41884 topic_id: 18778 reply_id: 115807[/import]

For the “old” sprite API you can use currentFrame = X.

EG, grab the runningcat.png from jungle scene and run this code;
[lua]require “sprite”

local sheet1 = sprite.newSpriteSheet( “runningcat.png”, 512, 256 )

local spriteSet1 = sprite.newSpriteSet(sheet1, 1, 8)
sprite.add( spriteSet1, “cat”, 1, 8, 1000, 0 )

local instance1 = sprite.newSprite( spriteSet1 )
instance1.x = 160
instance1.y = 240
instance1.xScale = .5
instance1.yScale = .5

instance1:prepare(“cat”)
local function example()
instance1.currentFrame = 5
end
timer.performWithDelay(2000, example, 1)[/lua]

That will work.
[import]uid: 52491 topic_id: 18778 reply_id: 115883[/import]

Thank you Peach, everything works now :slight_smile: [import]uid: 160159 topic_id: 18778 reply_id: 116021[/import]

De nada, happy to hear it’s all good now!

Peach :slight_smile: [import]uid: 52491 topic_id: 18778 reply_id: 116201[/import]