Jump to content


Photo

how to make sprite face direction


  • Please log in to reply
4 replies to this topic

#1 Simple-games

Simple-games

    GMC Member

  • New Member
  • 400 posts

Posted 26 January 2011 - 03:31 AM

In a platformer, how would I make the ai face the direction hes moving?

something like this?

if direction=270
{
image_xscale=1;
image_xscale=-1;
}

  • 0

Posted Image
Massive RPG platformer!
Play here


#2 8-BitTonberry

8-BitTonberry

    GMC Member

  • GMC Member
  • 675 posts
  • Version:GM:Studio

Posted 26 January 2011 - 03:55 AM

Well, for the direction, 270 is directly down.
(0 = right, 90 = up, 180 = left, 270 = down.)

image_xscale = -1 will flip the sprite horizontally. You're correct. =]
  • 1
8-BitTonberry.png

#3 Simple-games

Simple-games

    GMC Member

  • New Member
  • 400 posts

Posted 27 January 2011 - 02:53 AM

I forgot that I have:

draw_text(x,y-30,hp);
draw_sprite(sprite_index,0-8,x,y);

in the draw event. so it wont allow me to flip the sprite in the step event. Is there there another way i can do this?
  • 0

Posted Image
Massive RPG platformer!
Play here


#4 Silversuit

Silversuit

    GMC Member

  • New Member
  • 1 posts
  • Version:Unknown

Posted 29 May 2012 - 09:34 PM

I forgot that I have:

draw_text(x,y-30,hp);
draw_sprite(sprite_index,0-8,x,y);

in the draw event. so it wont allow me to flip the sprite in the step event. Is there there another way i can do this?


First time using this forum, and sorry this replies late to your comment, but let me try help ^^

Well, with your script to use flips, you need to be able to mess with the image_xscale and/or image_yscale variables.
In your script, you can change your...

draw_sprite(sprite_index,0-8,x,y);

...to...

draw_sprite_ext(sprite_index,0-8,x,y,IMAGE_XSCALE,IMAGE_YSCALE,IMAGE_ROTATION,c_white,1);

This should basically do what you want it to do if you set it right.
IMAGE_XSCALE should be 1 to be normal, or -1 to be flipped Horizontally. Larger/Smaller numbers will stretch the image.
IMAGE_YSCALE would do the same, but Vertically.
Whilst IMAGE_ROTATION can be any positive or negative number to spin your sprite. I think it's Negative to rotate Clockwise, Positive to rotate Counter-Clockwise.
Note with Rotating, if the number hits 360, it will act as if it's been set to 0 to continue spinning.


Also! I see a problem with your script saying "0-8" for the image_index slot.
This would give you the image_index of -8. This doesn't mean it would use sprites numbered 0 to 8.
Find another way around this, by either making a new variable or using image_index natrually.

Feel free to check the Manual for assistance when designing :)
  • 0

#5 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 12109 posts
  • Version:GM8

Posted 29 May 2012 - 11:50 PM

You will need the registered/pro version or GM 8.1 to use draw_sprite_ext(). If you have GM8.1, you can use draw_self() instead.
  • 0

"The problem with object-oriented languages is that they've got all this implicit environment that they carry around with them. You wanted a banana but what you've got is a gorilla holding the banana and the entire jungle." -Joe Armstrong

 

"It goes against the grain of modern education to teach children to program. What fun is there in making plans, acquiring discipline in organizing thoughts, devoting attention to detail and learning to be self-critical?" -Alan Perlis

 

"Do not think about where you want to be and how to get there; think about what you want to do and how to do it." -Theou Aegis





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users