Gradually change image animation speed?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Semicolonkid
Regular
Posts: 51
Joined: Tue Feb 14, 2017 6:13 pm
Projects: Summoned
itch: semicolonkid
Contact:

Gradually change image animation speed?

#1 Post by Semicolonkid »

So, I have an animated image:

Code: Select all

image Fidget:
	"fidget1.jpg"
	pause anim_speed
	"fidget2.jpg"
	pause anim_speed
	"fidget3.jpg"
	pause anim_speed
	"fidget4.jpg"
	pause anim_speed
	"fidget5.jpg"
	pause anim_speed
	repeat
#And then elsewhere, I initialize:
$ anim_speed = 0.04
I was hoping that adjusting anim_speed on the fly would automatically change the framerate of the animation. Instead, the animation's framerate only updates the next time it's "shown." So for example:

Code: Select all

$ anim_speed = 0.04
show Fidget 		#animation starts playing

$ anim_speed = 0.03 	#Does nothing

$ anim_speed = 0.03
show Fidget 		#Now it works, but it starts over
Basically, I have to restart the animation in order to change the speed, which causes a little jump. Is there a way for me to seamlessly, gradually change a playing animated image's pause speed?
Image

User avatar
Semicolonkid
Regular
Posts: 51
Joined: Tue Feb 14, 2017 6:13 pm
Projects: Summoned
itch: semicolonkid
Contact:

Re: Gradually change image animation speed?

#2 Post by Semicolonkid »

It's occurred to me that I probably should have asked this in the Ren'py questions forum. Sorry about that! I should know better.
Image

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Gradually change image animation speed?

#3 Post by gas »

You probably want to rotate that fidgetspinner...
You should create a function and use the function return as the rotation parameter.
https://www.renpy.org/dev-doc/html/atl. ... -statement
Then in your code you can pass a variable to that function to set the rotation speed.

Another idea, but I dunno if that work, is to create a transform that use parameters.

Code: Select all

transform trans(parameter):
    linear parameter rotate 15
    repeat
This way you can do:

Code: Select all

show thing with trans(parameter)
more than once with different parameter value AND PROBABLY you shouldn't see any "jump".

Anyway, mind that probably the actual best way is to use a CDD, entering the dread world of PyGame.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Gradually change image animation speed?

#4 Post by hell_oh_world »

as gas said use a function so should be something like this...

Code: Select all

init python:
  def var_speed(trans, st, at):
    trans.set_child("fidget{}.jpg".format(store.frame_num))

    store.frame_num += 1
    if store.frame_num > 5: # 5 since in your example you only have 5 frames for the animation.
      store.frame_num = 1

    return store.anim_speed

default frame_num = 1
default anim_speed = 0.04

image Fidget:
  function var_speed
or just do it inside a screen *i think*

Code: Select all

transform Fidget(anim_speed=0.04):
	"fidget1.jpg"
	pause anim_speed
	"fidget2.jpg"
	pause anim_speed
	"fidget3.jpg"
	pause anim_speed
	"fidget4.jpg"
	pause anim_speed
	"fidget5.jpg"
	pause anim_speed
	repeat

screen something():
  add Fidget(anim_speed)
  
label start:
  show screen something
  pause
not tried, but it should work.

User avatar
Semicolonkid
Regular
Posts: 51
Joined: Tue Feb 14, 2017 6:13 pm
Projects: Summoned
itch: semicolonkid
Contact:

Re: Gradually change image animation speed?

#5 Post by Semicolonkid »

You probably want to rotate that fidgetspinner...
Heheh, it's more complex than that: a frame-by-frame animation of a person fidgeting (and it uses more than 5 frames, but I was just trying to simplify the problem). Suffice to say, I'm afraid ATL transforms aren't gonna cut it.

or just do it inside a screen *i think*

Code: Select all

transform Fidget(anim_speed=0.04):
	"fidget1.jpg"
	pause anim_speed
	"fidget2.jpg"
	pause anim_speed
	"fidget3.jpg"
	pause anim_speed
	"fidget4.jpg"
	pause anim_speed
	"fidget5.jpg"
	pause anim_speed
	repeat

screen something():
  add Fidget(anim_speed)
  
label start:
  show screen something
  pause
not tried, but it should work.
I tried this one, but changing anim_speed still resets the animation. Also, there was a bizarre framerate effect where it would initially play slowly, then jump quickly, then loop at the right pace. This would only happen on the first loop, I assume because it's loading things into memory?

as gas said use a function so should be something like this...

Code: Select all

init python:
  def var_speed(trans, st, at):
    trans.set_child("fidget{}.jpg".format(store.frame_num))

    store.frame_num += 1
    if store.frame_num > 5: # 5 since in your example you only have 5 frames for the animation.
      store.frame_num = 1

    return store.anim_speed

default frame_num = 1
default anim_speed = 0.04

image Fidget:
  function var_speed
This, however, works!
Though one thing that concerns me a little: It plays more slowly than the original version, and this difference is very noticeable (almost double speed) at 0.02 for both of them. Then it catches back up again at 0.01, and the difference is also negligible at 0.1 or greater.
This doesn't matter at all UNLESS it's something a higher-end computer would fix? Because that would mean the animation could play at significantly different rates on different machines.

Anyway, I'll try to test it on different devices. No matter what, thank you both!!
Image

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]