How do I make a sprite shake?

0 favourites
  • 5 posts
From the Asset Store
Pixel Sprites ala ReactorCore - Builder Hardware - Large pack of sprites!
  • The goal is to temporarily shake a sprite, by just a few pixels, for a short amount of time.

    One example is how old beat-em-ups would shake a sprite on impact (seen here in Final Fight)

    There are some old forum links about it, but I couldn't find a concrete answer that didn't include a plugin.

    Thanks for any advice!

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I know you just said "doesn't include a plugin", but have you thought about writing your own plugin to do it?

    It would be pretty much a boiler plate behaviour with an action that makes the instance twitch a little bit by moving the X and Y coordinates. You could even add a couple of parameters to it to control how long the shaking should take and what the range of the shake should be.

    It's a perfect candidate for a behaviour.

  • Your confidence in my abilities is much appreciated! :) It sounds like you're right, but coding a plug-in is too far above my programming pay grade.

    I imagine it's possible with tweens or timers, but as you say it seems like a much more elegant (and I'd hoped, event-based) solution exists.

    Though maybe someone with more power than I could accomplish your idea!

  • You just move the sprite to self.x+value and back, repeat a few times.

    You can make a basic attempt by doing something like this

    set to self.x+10

    wait 0.1 seconds

    set to self.x-10

    wait 0.1 seconds

    set to self.x+10

    wait 0.1 seconds

    set to self.x-10

    Or you can put it in a function, replace the 10 and 0.1 with parameters to define the distance and how quickly it shakes.

  • Thanks lionz! This has helped a ton, and I've just adapted it to use timers (so I can pause the game mid-shake).

    And DiegoM, it was really helpful thinking about it as a behaviour, and making sure it could fit any object in the family.

    Cheers to you both!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)