Shake a sprite
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.
Shake a sprite
Is it possible to do a hpunch-like effect on a single sprite, not on the entire screen? What I'm trying to accomplish is two sprites on screen bumping into each other. So one sprite runs into the other and the "bumped" sprite shakes.
Right now I've used a custom-defined MoveTransition and shifting the sprite's xpos, but if there's a more efficient way I'd like to know it.
Right now I've used a custom-defined MoveTransition and shifting the sprite's xpos, but if there's a more efficient way I'd like to know it.
- PyTom
- Ren'Py Creator
- Posts: 16088
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
- Contact:
Re: Shake a sprite
ATL would be a good way to do it.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
Software > Drama • https://www.patreon.com/renpytom
Re: Shake a sprite
Oh, which ATL command would you say is best? I'm still no good with ATL, unfortunately >.<
Re: Shake a sprite
Code: Select all
transform hpunch_approximant:
linear 0.2 xoffset -20 #move left 20 pixel in 0.2 seconds
linear 0.2 xoffset +20 #move right 20 pixel in 0.2 seconds
repeat 5 #repeat the above 5 times
- ShippoK
- Veteran
- Posts: 348
- Joined: Wed Mar 28, 2012 8:59 pm
- Projects: Eyes of Gold (In-Progress)
- Organization: (Red Moon)
- Location: Glorious Nippon (A.K.A the USA)
- Contact:
Re: Shake a sprite
Fast, more like too slow? For a faster shake try something around 0.090 or less.Elmiwisa wrote:This is just my approximation of hpunch, it's too fast for me to see clearly.Code: Select all
transform hpunch_approximant: linear 0.2 xoffset -20 #move left 20 pixel in 0.2 seconds linear 0.2 xoffset +20 #move right 20 pixel in 0.2 seconds repeat 5 #repeat the above 5 times
Also, the +offset moves the character to the side while -offset keeps the character where they are.
Unless you want to move your character keep the +offset at 0/None.
Also, You don't need the transform hpunch_approximant: you can just use your image itself.
Code: Select all
ExampleCharacter_image:
linear 0.090 xoffset -10 #-offset to keep Character in place
linear 0.090 xoffset +0 #+offset to move Character
repeat 4 #Repeats
#linear = Pause (0.1 is one Second) (0.01 is one millisecond)
(Note; I am not an expert)
Much Appreciated for those who took the Survey!
Eyes of Gold [BL (Suspense) (+18)] IN-PROGRESS
Alternate Online [(Friendship) (+10)] ON-HOLD
•DeviantART• •[Honest critique] - 'Honesty is its own reward.'•
Eyes of Gold [BL (Suspense) (+18)] IN-PROGRESS
Alternate Online [(Friendship) (+10)] ON-HOLD
•DeviantART• •[Honest critique] - 'Honesty is its own reward.'•
Re: Shake a sprite
I agree with you that 0.2 is slow, but as I said, hpunch move too fast for me to actually time how much time the shake take, so I can't get an accurate value for timing. It can be adjusted easily if it looks slow.ShippoK wrote: Fast, more like too slow? For a faster shake try something around 0.090 or less.
Also, the +offset moves the character to the side while -offset keeps the character where they are.
Unless you want to move your character keep the +offset at 0/None.
Also, You don't need the transform hpunch_approximant: you can just use your image itself.
Hope this helps makes it more understanding.Code: Select all
ExampleCharacter_image: linear 0.090 xoffset -10 #-offset to keep Character in place linear 0.090 xoffset +0 #+offset to move Character repeat 4 #Repeats #linear = Pause (0.1 is one Second) (0.01 is one millisecond)
(Note; I am not an expert)
As for the rest of your post:
........................................................................................
1. Are you trying to claim that setting a value with a + to xoffset do something completely different from setting a value with a -? These are just stylistic differences you know.
2. The transform is because AERenoir want a character to shake went bumped into, not shaking right went the character first appeared.
3. linear is not the same as Pause. Pause (or more correctly, pause without the capital) do nothing, linear actually move the character. If the shaking is really fast it probably won't make a difference because nobody can see fast enough. But to get as similar to hpunch as possible, then it's a linear here.
4. 1 is 1 second. 0.1 is 0.1 second. 0.01 is 0.01 second. It's very direct. And "millisecond" means 0.001 second, in case you get that word wrong.
Re: Shake a sprite
Ooh, I'll try that. So where do I put this ATL block? *I fail* >.<
Re: Shake a sprite
Uh, it's a transform statement, so put it around where you declare your image, just to make it easier to organize. It doesn't matter where you put it really, as long as it's not inside some block.
Re: Shake a sprite
So the transform has to be declared at the init, right? And then when I need the sprite to shake I say "show charactersprite with pseudo-hpunch"?
Re: Shake a sprite
Yes.
If you don't put the transform statement in a block, it automatically run as if it is in an init block.
If you don't put the transform statement in a block, it automatically run as if it is in an init block.
- rusicaria
- Regular
- Posts: 84
- Joined: Sat Mar 28, 2020 12:26 am
- Projects: VivaCity (VN)
- Tumblr: rusicariaGAMES
- itch: rusicariaGAMES
- Contact:
Re: Shake a sprite
Hey, so I know this is an old thread, but seeing as I spent ages trying to find an answer I figured I'd reply with what I found here:
viewtopic.php?t=19429
Donmai's reply basically explains it step by step, so for anyone who is extremely new to coding, if you're going to use the tranform command, make sure to define the command first:
and then script in the transform command:
btw if you want the sprite to shake vertically rather than horizontally, just change all the xoffsets's to yoffsets's, and credit to Donmai who's coding I used for this.
then to use on a sprite:
viewtopic.php?t=19429
Donmai's reply basically explains it step by step, so for anyone who is extremely new to coding, if you're going to use the tranform command, make sure to define the command first:
Code: Select all
init python:
define.move_transitions("shake/whatever you want to name it", 1.0)
Code: Select all
transform shake:
ease .06 xoffset 24
ease .06 xoffset -24
ease .05 xoffset 20
ease .05 xoffset -20
ease .04 xoffset 16
ease .04 xoffset -16
ease .03 xoffset 12
ease .03 xoffset -12
ease .02 xoffset 8
ease .02 xoffset -8
ease .01 xoffset 4
ease .01 xoffset -4
ease .01 xoffset 0
then to use on a sprite:
Code: Select all
label example:
show character at shake
- Donmai
- Eileen-Class Veteran
- Posts: 1958
- Joined: Sun Jun 10, 2012 1:45 am
- Completed: Toire No Hanako, Li'l Red [NaNoRenO 2013], The One in LOVE [NaNoRenO 2014], Running Blade [NaNoRenO 2016], The Other Question, To The Girl With Sunflowers
- Projects: Slumberland
- Location: Brazil
- Contact:
Re: Shake a sprite
Thanks, but I only wrote the detailed instructions. The transform itself was written by nyaatrap
viewtopic.php?p=251409#p251409
No, sorry! You must be mistaking me for someone else.
TOIRE NO HANAKO (A Story About Fear)
TOIRE NO HANAKO (A Story About Fear)
Who is online
Users browsing this forum: Semrush [Bot]