Login | Register

Eight angles direction

August 9, 2006, 00:16 by Calle
[loading]
-->
Eight directional in coding
First of all you need to decide what key combinations will turn which way. Usually it would be the arrow keys, up is up, the right is right etc. the right key in combination with the up key is up-right. Eight directions are one direction each 45 degrees, calculated by dividing 360 by eight.

draw_sprite_ext(sprite_index,0,x,y,1,1,rot,-1,1);

Now all you need to do is to decide what value rot should have, if in overview. We will discuss other view later but in overview it works perfectly fine just to rotate the sprite in the fancied angle. The code that I use will make it necessary to use many events. This might seem rather clumsy, but in fact it is also rather clumsy to put it all into one single code. Being specific in each event will actually save us a whole lot of rows and unnecessary checks.

if (keyboard_check(vk_left)) {
rot = 45;
}
if (keyboard_check(vk_right)) {
rot = 135;
}


Is the simple code that we got then, it’s just an example code that you must configure for each event and set the right angles.

For isometric games you might want to change sprite instead of rotating, and then you may just change rot = into sprite_index = …

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games