I looked in the APIs, and I can’t figure out how to get a single frame of a sprite to display, as in movieclip’s function stopAtFrame. Can anyone help me?
C [import]uid: 147322 topic_id: 32679 reply_id: 332679[/import]
I looked in the APIs, and I can’t figure out how to get a single frame of a sprite to display, as in movieclip’s function stopAtFrame. Can anyone help me?
C [import]uid: 147322 topic_id: 32679 reply_id: 332679[/import]
Are you using the old sprite library or the new method?
I think the old library uses sprite.frame = frameNumber
. The new imageSheet-based method uses sprite:setFrame = frameNumber
Brent [import]uid: 9747 topic_id: 32679 reply_id: 129912[/import]
I’m using whichever one does not require using “require(“sprite”).” So if that’s the old one or the new one, that’s what I’m using. [import]uid: 147322 topic_id: 32679 reply_id: 129915[/import]
It’s the latter then, although the format is actually
spriteObject:setFrame(framenumber)
The only restriction is that if you’ve set it to a sequence that has only a small number of frames, then not every frame is accesible to you with :setFrame() [import]uid: 41884 topic_id: 32679 reply_id: 129917[/import]
What do you mean by that? [import]uid: 147322 topic_id: 32679 reply_id: 129923[/import]
Are you using the old sprite library or the new method?
I think the old library uses sprite.frame = frameNumber
. The new imageSheet-based method uses sprite:setFrame = frameNumber
Brent [import]uid: 9747 topic_id: 32679 reply_id: 129912[/import]
I’m using whichever one does not require using “require(“sprite”).” So if that’s the old one or the new one, that’s what I’m using. [import]uid: 147322 topic_id: 32679 reply_id: 129915[/import]
It’s the latter then, although the format is actually
spriteObject:setFrame(framenumber)
The only restriction is that if you’ve set it to a sequence that has only a small number of frames, then not every frame is accesible to you with :setFrame() [import]uid: 41884 topic_id: 32679 reply_id: 129917[/import]
What do you mean by that? [import]uid: 147322 topic_id: 32679 reply_id: 129923[/import]
How are you setting it up?
If you are defining sequences for your animation, then do something like the following:
-- local spriteSheet = [your sprite data]
local sequenceData = {
{name = "running", start = 1, count = 30, time = 500},
{name = "jumping", start = 1, count = 1}
}
local player = display.newSprite( spriteSheet, sequenceData )
The running sequence is the one that plays through every frame (assuming a 30 frame spritesheet). When I want it to stick on the first frame, I call:
player:setSequence( "jumping" )
player:play()
Hope this helps. If you’re setting up the sprite differently, there may still be a way to do what you’re asking but it’s impossible to tell without seeing your code.
-Treb [import]uid: 181948 topic_id: 32679 reply_id: 129968[/import]
I’m actually not using sprites for playing animations. I’m using them for making a tiled background, like Tiled makes. I don’t know if it’s leaky or not - if it is, please tell me. It’s working with the setFrame function.
Thanks for everyone’s help!
One more question:
What does richard9 mean by “…if you’ve set it to a sequence that has only a small number of frames, then not every frame is accesible to you with :setFrame()” [import]uid: 147322 topic_id: 32679 reply_id: 129979[/import]
How are you setting it up?
If you are defining sequences for your animation, then do something like the following:
-- local spriteSheet = [your sprite data]
local sequenceData = {
{name = "running", start = 1, count = 30, time = 500},
{name = "jumping", start = 1, count = 1}
}
local player = display.newSprite( spriteSheet, sequenceData )
The running sequence is the one that plays through every frame (assuming a 30 frame spritesheet). When I want it to stick on the first frame, I call:
player:setSequence( "jumping" )
player:play()
Hope this helps. If you’re setting up the sprite differently, there may still be a way to do what you’re asking but it’s impossible to tell without seeing your code.
-Treb [import]uid: 181948 topic_id: 32679 reply_id: 129968[/import]
If you have defined a sequence (a subset of the image sheet), then when you set a frame it is based on the frames that are in the currently set sequence, not the frames in the whole image sheet. [import]uid: 40033 topic_id: 32679 reply_id: 129983[/import]
I’m actually not using sprites for playing animations. I’m using them for making a tiled background, like Tiled makes. I don’t know if it’s leaky or not - if it is, please tell me. It’s working with the setFrame function.
Thanks for everyone’s help!
One more question:
What does richard9 mean by “…if you’ve set it to a sequence that has only a small number of frames, then not every frame is accesible to you with :setFrame()” [import]uid: 147322 topic_id: 32679 reply_id: 129979[/import]
If you have defined a sequence (a subset of the image sheet), then when you set a frame it is based on the frames that are in the currently set sequence, not the frames in the whole image sheet. [import]uid: 40033 topic_id: 32679 reply_id: 129983[/import]
Now I understand. Thanks again for all the help!
Caleb [import]uid: 147322 topic_id: 32679 reply_id: 130021[/import]
Now I understand. Thanks again for all the help!
Caleb [import]uid: 147322 topic_id: 32679 reply_id: 130021[/import]