Rotating sprites with allegro?
Is there anyone who uses Allegro and know how to rotate a sprite or bitmap with a 360 degree scale instead of 256. I want to know this because i´m supposed to make the player be able to rotate and then walk in that direction. Examples are welcome, 256 degree or 360 degree.
Anybody who knows how to accomplish this?
Anyone can do it!
Yep. To rotate any sprite, call the function:
rotate_sprite(BITMAP* to, BITMAP* from, int x, int y, int ang);
It''s something like that... maybe the name of the parameters ias a bit off, but that''s the correct order. The ang must be in fixed point, so call itofix() on your angle, which must be in radians. I think that''s about it... and that will rotate the spirte to any one of 360 degrees. Of course, it won''t make your player ''move'' in that direction, but i''m guessing you know that (and how to do it). Good luck!
Insomnia
rotate_sprite(BITMAP* to, BITMAP* from, int x, int y, int ang);
It''s something like that... maybe the name of the parameters ias a bit off, but that''s the correct order. The ang must be in fixed point, so call itofix() on your angle, which must be in radians. I think that''s about it... and that will rotate the spirte to any one of 360 degrees. Of course, it won''t make your player ''move'' in that direction, but i''m guessing you know that (and how to do it). Good luck!
Insomnia
Insomnia
Yes, i knew that i should use rotate_sprite(...);, but the thing i don´t know is how to move the player in that direction. I tried but the player moves totally weird so i need help with that. Please.
Anyone can do it!
Oh, I see. Well, then your problem certainly doesn''t lie with how you''r going to draw your player . Have you ever learned trigonometry? If not, you should have . Basically, you need to add the sine of the angle to the players y coordinate, and the cosine of the angle to the player''s x angle. Simple! He''ll move in the direction of the angle you specified. If you can''t take the info i''ve given you and work it into a solution, perhaps you need to backtrack a bit and relearn some trig, & math... let me know if you have any problems !
Insomnia
Insomnia
Insomnia
Assuming that info is correct (I use it in my games, but I can''t remember if sin or cos goes with which coord), let me elaborate.
x += cos(AngleInRadians) * Velocity;
y += sin(AngleInRadians) * Velocity;
It will move at Velocity in the direction of AngleInRadians.
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
x += cos(AngleInRadians) * Velocity;
y += sin(AngleInRadians) * Velocity;
It will move at Velocity in the direction of AngleInRadians.
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
Visit the ROAD Programming Website for more programming help.
--------------------
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor
quote:
Original post by Yanroy
Assuming that info is correct (I use it in my games, but I can''t remember if sin or cos goes with which coord)
Of course it''s correct . I wouldn''t post half arsed crap. In 2d movement, x should be determined by cosine, y by sine. I promise . Anyway, yeah, sorry, I forgot to mention that
sin(x)+cos(x) = 1
That is to say, that the sine plus the cosine of any angle will be 1... so your player''s movement will be 1 ''unit'' per frame. As Yanroy said, therefore multiplying this by a velocity value will give you the proper speed you want, per frame. Logical really. Also, might I suggest you put the sin / cos values in a look up table... I always do... every program... maakes life much easier too .
Insomnia
Insomnia
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement