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.
Change Sprite Depending On Direction
Started by Sticky Note, Jun 06 2007 03:00 AM
5 replies to this topic
#1
Posted 06 June 2007 - 03:00 AM
#2
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:
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.
#3
Posted 06 June 2007 - 03:06 AM
Well, the moving object is one that is not controlled by the player, so... yeah.
#4
Posted 06 June 2007 - 03:08 AM
The "spr.direction".Well, the moving object is one that is not controlled by the player, so... yeah.
#5
Posted 06 June 2007 - 03:25 AM
Don't you need registered for sprite.direction? I don't have registered.
#6
Posted 06 June 2007 - 04:09 AM
Usually it would look like this:
Some may prefer this way:
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 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











