Jump to content


Photo

Change Sprite Depending On Direction


  • Please log in to reply
5 replies to this topic

#1 Sticky Note

Sticky Note

    GMC Member

  • New Member
  • 1326 posts

Posted 06 June 2007 - 03:00 AM

Simple version: the object only moves left, right, up, and down. Could I use:

Step:
if (object_direction = 0) {object_sprite = spr_left}
if (object_direction = 90) {object_sprite = spr_up}
if (object_direction = 180) {object_sprite = spr_right}
if (object_direction = 270) {object_sprite = spr_down}

Advanced version: the object can move in any direction. Is there a way I can make a range (like if (object_direction = 315 through 45) {object_sprite = spr_up}), instead of the straight directions?

Also, if my codes above are incorrect, please correct them for me. That would be greatly appreciated.

Tell me if I am unclear.
  • 0

#2 aeharding

aeharding

    GMC Member

  • New Member
  • 462 posts

Posted 06 June 2007 - 03:02 AM

Looks like it works for me! But, it will only work if the sprite is exactly that degree. And, it would be just "direction" for the same object being changed. "object.direction" if not.

I would use key_press and then change it to the sprite.

For advanced version:
(have not checked)
Something like:
if mainplayer.direction < 90
{
  if mainplayer.direction > 180
  {
    object_sprite = spr_left
  }
}

Edited by aeharding, 06 June 2007 - 03:10 AM.

  • 0

#3 Sticky Note

Sticky Note

    GMC Member

  • New Member
  • 1326 posts

Posted 06 June 2007 - 03:06 AM

Well, the moving object is one that is not controlled by the player, so... yeah.
  • 0

#4 aeharding

aeharding

    GMC Member

  • New Member
  • 462 posts

Posted 06 June 2007 - 03:08 AM

Well, the moving object is one that is not controlled by the player, so... yeah.

<{POST_SNAPBACK}>

The "spr.direction".
  • 0

#5 Sticky Note

Sticky Note

    GMC Member

  • New Member
  • 1326 posts

Posted 06 June 2007 - 03:25 AM

Don't you need registered for sprite.direction? I don't have registered.
  • 0

#6 torigara

torigara

    GMC Member

  • GMC Member
  • 6507 posts

Posted 06 June 2007 - 04:09 AM

Usually it would look like this:
if (object_direction >= 45 && object_direction < 135) {
    // up
}
else if (object_direction >= 135 && object_direction < 225) {
    // left
}
else if (object_direction >= 225 && object_direction < 315) {
    // bottom
}
else /*if (object_direction >= 315 || object_direction < 45)*/ {
    // right
}
The last if after else isn't necessary, but if you include it, note that you have to use "or" instead of "and" for the last condition.

Some may prefer this way:
switch ((round(object_direction)/90) mod 4) {
    case 0:
        // right
        break;
    case 1:
        // up
        break;
    csae 2:
        // left
        break;
    case 3:
        // down
        break;
}
To Sticky Note: you don't have to be registered to use direction. Perhaps you're mixing it up with image_angle. (Anyway, you can look up the manual to confirm it.)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users