Just a few short questions.
Is it possible to have an animation play when a button is clicked?
And is it possible to change the animation's position based on the mouse cursor's current position?
For example: an arcade shooter game, clicking plays an animation of a bullet being fired at the cursor's current position.
Thank you for your time, I appreciate any input and suggestions.
Animation on Mouse Click and Position
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.
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.
Re: Animation on Mouse Click and Position
I've been using something like this, for a different purpose, but with some adjustment it may be useful:
Position() can be replaced with your own ATL as longs as it places the animation in an xpos and ypos.
Shooting targets should be buttons too, and I think they should have those actions too so the animation displays when you click them.
Code: Select all
image fire_bullet = "fire.png" #should be an ATL animation, I'm using a static image for testing
screen test():
$ mouse_pos = renpy.get_mouse_pos() #set a screen variable to the mouse current position
#this button will be the shooting area
button:
xsize 1280 #this should be the size of the shootable area, if it's not the whole screen
ysize 720
action [Function(renpy.show, 'fire_bullet', at_list=[Position(xpos=mouse_pos[0], ypos=mouse_pos[1])]), #show the animation
SensitiveIf(not renpy.showing('fire_bullet')) #make sure it doesn't fire if a bullet is already being fired, so it does not cut the anim midway
]
timer 0.05 repeat True action SetScreenVariable('mouse_pos', renpy.get_mouse_pos()) #update the mouse position every 0.05 seconds
if renpy.showing('fire_bullet'):
timer 1 repeat True action Function(renpy.hide, 'fire_bullet') #Hide the image after the animation is complete, so the button can be clicked again.
Position() can be replaced with your own ATL as longs as it places the animation in an xpos and ypos.
Shooting targets should be buttons too, and I think they should have those actions too so the animation displays when you click them.
Who is online
Users browsing this forum: Ahrefs [Bot], Ocelot