Question about new Sprite API

I’ve noticed there is no way to “stop” an animation under the new Sprite API scheme.

You can pause it by doing an object:pause(). Under the old Sprite scheme you could “stop” an animation by using an object:prepare() statement.

Has anyone found a work-around for this yet? I am using the pause command to pause animations when my pause button is pushed and I don’t want to inadvertently “restart” an animation that is supposed to be stopped by unpausing my game. I may want to restart the animation later under program control when a series of events occurs with a play command but I don’t want it to start up by accident.

Thanks for any info.
-Dennis
[import]uid: 108253 topic_id: 31112 reply_id: 331112[/import]

Hi Dennis,

If you are pausing all of your animations, I assume you have them stored in a Lua table or somewhere, such that you can loop through them all and pause them on “game pause”. I do that in my games because there isn’t a way to pause all sprites with one command.

So assuming you have that (or even if you don’t), you can just assign a sub-variable to your sprites when you create them, for example:

sprite1.playOnResume = [true or false]

If you want a sprite to “stop” and not auto-resume, pause it, and also set the state variable to “false”. Then, when you unpause the game and loop through your sprites, only unpause those sprites which are “true” to resume playing.

Yes, all of this is a bit more work on your part, but the state variables stay attached to the sprites for easy management.

Brent [import]uid: 9747 topic_id: 31112 reply_id: 124481[/import]

Is there a way to either manually set the current frame (and animate it yourself) or adjust the time parameter between frames for sprite sequences?

I just started playing with the new API using some Sonic spritesheets. I’m starting with the ‘walk’ animation before he starts to sprint, where he starts off walking very slowly, then breaks into a jog before the sprint animation takes over.

The only way I’ve found to do it is to set up various sequences, i.e. walk1, walk2, walk3, with decreasing time parameters and keep changing the sequence the longer the user holds down left or right. [import]uid: 93133 topic_id: 31112 reply_id: 124499[/import]

Thanks Brent,
I suspected as much on the pause versus stop issue. I like your solution better than mine however.
If you don’t mind I’ll use it. I have a whole pause and unpause routine where I also loop through all the sprites.
It does suggest that maybe Corona should consider a global pause and unpause for sprites since most all games offer a pause function.

Also Nick have you tried using the object.timeScale parameter? I haven’t had a need to use it yet but it seems it might offer you the solution to changing the animation rate. You could loop the animation indefinitely and then pause the animation when the user releases the button.

Thanks all,
-Dennis
[import]uid: 108253 topic_id: 31112 reply_id: 124569[/import]

Hi Dennis,
Certainly you can use my suggested method if it’s practical in your game. I also wish that there was a “pause all sprites” command in Corona, and I have suggested it in the past. In fact, I wish there was a way to pause the entire engine… physics, sprites, timers, transitions… all in one command! Of course, it’s easy for me to request that, but at the engineering level it’s probably FAR more complex.

Brent
[import]uid: 9747 topic_id: 31112 reply_id: 124573[/import]

@dennis, that’s great, thanks.

I have however now encountered another problem. I’ve got two d-pad buttons, while one of them is held down I increase the sonic.timeScale variable by 0.01 each frame and the animation speeds up. I move sonic.x in proportion to the timeScale value, and the camera in the opposite direction.

When I release the button, I set the timeScale value back to 0.05 and the animation stops.

Now when I press a button again, the animation goes back to the speed it was when I last released the button. I’m printing sonic.timeScale to screen and it is as expected, but the sprite animation speed doesn’t match up.

[import]uid: 93133 topic_id: 31112 reply_id: 124621[/import]

Hi Nick,
I assume you also did an object:pause() when you release the button?

Hmm… it sounds kind of like a bug. If you set the proper object.timescale back to almost zero it should cause the animation to almost stop. If it is resuming the animation with the last timescale you had when
the button was pressed then it seems it is a bug. I assume you did an object:play() to restart the animation?
You should submit it as a bug with a very simple code sample to get the best response from Corona.
I find that if I write a new main.lua with just one test sprite and one button read and a couple of print statements to the terminal to show that the timescale value is set back to almost zero then the tech guys at Corona don’t have to spend any time to verify the bug and respond to it. Of course I mean fix it.

Good luck,
-Dennis

P.S. When I send them a bug, I create an entire new directory with just the minimal number of files in it and then I zip the whole directory and attach it to the bug report. Since those guys are always looking at hundreds of bugs at any moment you are more likely to get a response the simpler you can make it. [import]uid: 108253 topic_id: 31112 reply_id: 124626[/import]

Hi Dennis,

If you are pausing all of your animations, I assume you have them stored in a Lua table or somewhere, such that you can loop through them all and pause them on “game pause”. I do that in my games because there isn’t a way to pause all sprites with one command.

So assuming you have that (or even if you don’t), you can just assign a sub-variable to your sprites when you create them, for example:

sprite1.playOnResume = [true or false]

If you want a sprite to “stop” and not auto-resume, pause it, and also set the state variable to “false”. Then, when you unpause the game and loop through your sprites, only unpause those sprites which are “true” to resume playing.

Yes, all of this is a bit more work on your part, but the state variables stay attached to the sprites for easy management.

Brent [import]uid: 9747 topic_id: 31112 reply_id: 124481[/import]

Is there a way to either manually set the current frame (and animate it yourself) or adjust the time parameter between frames for sprite sequences?

I just started playing with the new API using some Sonic spritesheets. I’m starting with the ‘walk’ animation before he starts to sprint, where he starts off walking very slowly, then breaks into a jog before the sprint animation takes over.

The only way I’ve found to do it is to set up various sequences, i.e. walk1, walk2, walk3, with decreasing time parameters and keep changing the sequence the longer the user holds down left or right. [import]uid: 93133 topic_id: 31112 reply_id: 124499[/import]

Thanks Brent,
I suspected as much on the pause versus stop issue. I like your solution better than mine however.
If you don’t mind I’ll use it. I have a whole pause and unpause routine where I also loop through all the sprites.
It does suggest that maybe Corona should consider a global pause and unpause for sprites since most all games offer a pause function.

Also Nick have you tried using the object.timeScale parameter? I haven’t had a need to use it yet but it seems it might offer you the solution to changing the animation rate. You could loop the animation indefinitely and then pause the animation when the user releases the button.

Thanks all,
-Dennis
[import]uid: 108253 topic_id: 31112 reply_id: 124569[/import]

Hi Dennis,
Certainly you can use my suggested method if it’s practical in your game. I also wish that there was a “pause all sprites” command in Corona, and I have suggested it in the past. In fact, I wish there was a way to pause the entire engine… physics, sprites, timers, transitions… all in one command! Of course, it’s easy for me to request that, but at the engineering level it’s probably FAR more complex.

Brent
[import]uid: 9747 topic_id: 31112 reply_id: 124573[/import]

@dennis, that’s great, thanks.

I have however now encountered another problem. I’ve got two d-pad buttons, while one of them is held down I increase the sonic.timeScale variable by 0.01 each frame and the animation speeds up. I move sonic.x in proportion to the timeScale value, and the camera in the opposite direction.

When I release the button, I set the timeScale value back to 0.05 and the animation stops.

Now when I press a button again, the animation goes back to the speed it was when I last released the button. I’m printing sonic.timeScale to screen and it is as expected, but the sprite animation speed doesn’t match up.

[import]uid: 93133 topic_id: 31112 reply_id: 124621[/import]

Hi Nick,
I assume you also did an object:pause() when you release the button?

Hmm… it sounds kind of like a bug. If you set the proper object.timescale back to almost zero it should cause the animation to almost stop. If it is resuming the animation with the last timescale you had when
the button was pressed then it seems it is a bug. I assume you did an object:play() to restart the animation?
You should submit it as a bug with a very simple code sample to get the best response from Corona.
I find that if I write a new main.lua with just one test sprite and one button read and a couple of print statements to the terminal to show that the timescale value is set back to almost zero then the tech guys at Corona don’t have to spend any time to verify the bug and respond to it. Of course I mean fix it.

Good luck,
-Dennis

P.S. When I send them a bug, I create an entire new directory with just the minimal number of files in it and then I zip the whole directory and attach it to the bug report. Since those guys are always looking at hundreds of bugs at any moment you are more likely to get a response the simpler you can make it. [import]uid: 108253 topic_id: 31112 reply_id: 124626[/import]