Page 1 of 1

Shake a sprite

Posted: Sat Sep 28, 2013 5:06 am
by AERenoir
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.

Re: Shake a sprite

Posted: Sat Sep 28, 2013 11:23 am
by PyTom
ATL would be a good way to do it.

Re: Shake a sprite

Posted: Sat Sep 28, 2013 1:19 pm
by AERenoir
Oh, which ATL command would you say is best? I'm still no good with ATL, unfortunately >.<

Re: Shake a sprite

Posted: Sat Sep 28, 2013 1:30 pm
by Elmiwisa

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
This is just my approximation of hpunch, it's too fast for me to see clearly.

Re: Shake a sprite

Posted: Sun Sep 29, 2013 3:07 am
by ShippoK
Elmiwisa wrote:

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
This is just my approximation of hpunch, it's too fast for me to see clearly.
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.

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)
Hope this helps makes it more understanding.
(Note; I am not an expert)

Re: Shake a sprite

Posted: Sun Sep 29, 2013 8:27 am
by Elmiwisa
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.

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)
Hope this helps makes it more understanding.
(Note; I am not an expert)
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.
As for the rest of your post:

........................................................................................ :roll:

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

Posted: Wed Oct 02, 2013 1:36 am
by AERenoir
Ooh, I'll try that. So where do I put this ATL block? *I fail* >.<

Re: Shake a sprite

Posted: Sat Oct 05, 2013 2:27 am
by Elmiwisa
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

Posted: Fri Oct 11, 2013 10:57 am
by AERenoir
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

Posted: Sun Oct 13, 2013 1:56 am
by Elmiwisa
Yes.
If you don't put the transform statement in a block, it automatically run as if it is in an init block.

Re: Shake a sprite

Posted: Sun Apr 18, 2021 7:02 pm
by rusicaria
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:

Code: Select all

init python:
    define.move_transitions("shake/whatever you want to name it", 1.0)
and then script in the transform command:

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
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:

Code: Select all

label example:
    show character at shake

Re: Shake a sprite

Posted: Mon Apr 19, 2021 5:48 pm
by Donmai
rusicaria wrote: Sun Apr 18, 2021 7:02 pmand credit to Donmai
Thanks, but I only wrote the detailed instructions. The transform itself was written by nyaatrap
viewtopic.php?p=251409#p251409