0 Favourites

How to prevent sprite rotation for 8-dir movement

  • Okay, here's what I've done:

    1. I used the jeep sprites from the 'battlefield' sprite pack to create a Jeep object with animations for moving up, down, left, right, etc.

    2. I assigned 8-direction movement to the Jeep.

    3. I created keypress events so that pressing up/down/left/right would set the right animation.

    My problem is that whenever you move, the sprite rotates. But since the animations are already "pre-rotated", you end up with a very wrong sprite (like the 'up' animation rotated on its side).

    What's the best way to fix this? I can't find an elegant way to disable rotation. Should I just set a per-frame event to force the Jeep's angle to zero? Or would that screw up other things (like created bullets would inherit angle zero too, regardless of the direction we're going)?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Easiest solution that comes to mind: have an invisible "Player" sprite that has the 8dir movement, and have the Jeep sprite attached to it by way of "Every tick: Jeep - Set position to Player.X, Player.Y".

    It's a handy trick for many types of games when it comes to controlling animations. <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Make sure that in the properties of the 8 direction behavior you have set the "Set angle" property to "No".

    From the manual

    et angle

    Whether or not the movement should also affect the objects angle. 360 degree (smooth) will always set the object's angle to the current angle of motion. 45-degree intervals will set the object's angle to 8 possible directions. 90-degree intervals will set the object's angle to 4 possible directions. No means the behavior will not set the object's angle at all, which is useful if you want to control this yourself with events (e.g. to make the object point towards the mouse cursor).

  • Is there a good solution for adjusting the animation frame for isometric sprites in that case?

    In my code I do it like this:

    +For every Jeep:

    ->Set Animation Frame= (Self.CustomMovement.Angle>45 & Self.CustomMovement.Angle<135) ? DOWN_SPRITE_FRAME : Self.Frame

    ->Set Animation Frame= (Self.CustomMovement.Angle>=135 & Self.CustomMovement.Angle<225) ? LEFT_SPRITE_FRAME : Self.Frame

    etc.

  • r0j0 did that a while ago.. might answer your question

    r0j0_8dir.capx

  • Ooooh clever. I like it <img src="smileys/smiley20.gif" border="0" align="middle" />

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