sprite.timeScale

I’m new to Corona but loving it so far.
I’ve gotten quite deep into it without having to post to the forums, but I’m running into something weird right now. When using sprite.timeScale, my animation doesn’t go any faster or slower, no matter what value.
Here’s the code I’m using:

[lua]-----
require(“sprite”);
local data = require(“dance”).getSpriteSheetData();
local sheet = sprite.newSpriteSheetFromData(“dance.png”, data);
local set = sprite.newSpriteSet(sheet, 1, 109);

local function spriteEvent(pEvent)
if pEvent.phase == “end” then
pEvent.sprite:removeEventListener(“sprite”, spriteEvent)
pEvent.sprite:removeSelf();
end
end

local function touchEvent(pEvent)
local instance = sprite.newSprite(set);
instance.timeScale = 20;
instance.x = pEvent.x;
instance.y = pEvent.y;
instance:play();
instance:addEventListener(“sprite”, spriteEvent);
end
-----[/lua]

Every time you touch the screen, the sprite is created; this all works fine. But there’s no difference in speed when I change the timescale. Did I forget something?

Any help would be awesome.

-E [import]uid: 71962 topic_id: 11780 reply_id: 311780[/import]

Nobody?
Hm, ok… guess I’ll have to figure something else out…
-E [import]uid: 71962 topic_id: 11780 reply_id: 42981[/import]

I just tested spriteInstance.timeScale and it doesn’t work for me either. Looks like a bug. [import]uid: 27183 topic_id: 11780 reply_id: 44404[/import]

Hmm it seems like timeScale does work but not for the values advertised in the docs. In one complex example it didn’t work, in another example I was able to double and halve the speed.

Update: In my complex example it works. It seems like I can’t go faster than 2x though at higher speeds it is tough to tell. I can definitely slow down the animation though. [import]uid: 27183 topic_id: 11780 reply_id: 44416[/import]

Sorry for waking up a zombie thread but I have the same problem too, been looking around for solutions in several threads but it seems some people are doing with no problem and I got stuck with the same speed all the time.

How are you guys doing with the timeScale issue ? [import]uid: 76697 topic_id: 11780 reply_id: 117485[/import]

Hi yanuar,

Can you post a sample? Also, what build are you using? [import]uid: 27183 topic_id: 11780 reply_id: 117552[/import]

Hi Don,

local loqsprite = require('loq\_sprite')  
  
spritefactory = loqsprite.newFactory('gfx.others')  
  
local newSprite=spritefactory:newSpriteGroup("efek\_charge")  
newSprite.x=400  
newSprite.y=400  
newSprite:timeScale(6)  
newSprite:play()  

no matter what timeScale I used the animation will play in the same speed [import]uid: 76697 topic_id: 11780 reply_id: 117606[/import]

oh and i’m still using build 813 [import]uid: 76697 topic_id: 11780 reply_id: 117608[/import]

@yanuar: Did you ever solve this? I’m having the same issue on build 894. Setting the timeScale appears to work, as I can print it to the console and it did indeed change. But there is no visible difference with the animation. [import]uid: 149111 topic_id: 11780 reply_id: 126644[/import]

yes I have, if you’re using the spriteFactory from the spriteloq you need to edit it abit. The problem with timescale happens because you’re most likely using the old sprite class (or generate them in the old way).
Corona has change the sprite class (and how to create them), I believe it’s now part of display class.

Please check the documentation on sprite, that should help you getting the timescale working properly [import]uid: 76697 topic_id: 11780 reply_id: 126646[/import]

@yanuar: Thanks for the reply! I’m actually already using display.newSprite() and not the older sprite library. Also, for what it’s worth, the imageSheets I’m using are being generated by TexturePacker.

I’ve gone through the timeScale documentation, and haven’t seen anything to tip me off to the problem.

If I do this…

[lua]local newActor = display.newSprite(imageSheet, sequenceDate)
newActor.timeScale = 10.0
newActor:setSequence(“walk”)
newActor:play()[/lua]

…the sprite animates at normal speed. The value I enter for timeScale doesn’t seem to matter. [import]uid: 149111 topic_id: 11780 reply_id: 126665[/import]

iirc, it only works if you use certain range like 0.5 - 2. Have you tried using < 1 timescale? I’m on a trip and have no access to my dev machine to check it out. [import]uid: 76697 topic_id: 11780 reply_id: 126677[/import]

@yanuar: Did you ever solve this? I’m having the same issue on build 894. Setting the timeScale appears to work, as I can print it to the console and it did indeed change. But there is no visible difference with the animation. [import]uid: 149111 topic_id: 11780 reply_id: 126644[/import]

yes I have, if you’re using the spriteFactory from the spriteloq you need to edit it abit. The problem with timescale happens because you’re most likely using the old sprite class (or generate them in the old way).
Corona has change the sprite class (and how to create them), I believe it’s now part of display class.

Please check the documentation on sprite, that should help you getting the timescale working properly [import]uid: 76697 topic_id: 11780 reply_id: 126646[/import]

@yanuar: Thanks for the reply! I’m actually already using display.newSprite() and not the older sprite library. Also, for what it’s worth, the imageSheets I’m using are being generated by TexturePacker.

I’ve gone through the timeScale documentation, and haven’t seen anything to tip me off to the problem.

If I do this…

[lua]local newActor = display.newSprite(imageSheet, sequenceDate)
newActor.timeScale = 10.0
newActor:setSequence(“walk”)
newActor:play()[/lua]

…the sprite animates at normal speed. The value I enter for timeScale doesn’t seem to matter. [import]uid: 149111 topic_id: 11780 reply_id: 126665[/import]

iirc, it only works if you use certain range like 0.5 - 2. Have you tried using < 1 timescale? I’m on a trip and have no access to my dev machine to check it out. [import]uid: 76697 topic_id: 11780 reply_id: 126677[/import]

I used display.newSprite() as well. Accepted value is ranged between 0.05 to 20.00.

And it works well.

But i got another problem. I change the timeScale on runtime, and it seems the animation keep restarting to its first frame.

Is there anyone can confirm about this?

And is there a way to keep the last frame?

Thanks before…

@wilychristian: I actually never went back and tried using timeScale again, but what you might do is pause the animation, store the current frame number, change timeScale, set the frame to the frame number you stored, and then play.

Hi @wilychristian,

David is basically correct: you should read/get the current frame (no need to pause the animation), change the timescale, and then skip to that frame number.

Brent

Okay so it does restart.

Thanks David and Brent.

And as Brent wrote, we can use setFrame() without pausing the animation.