GameMakerHelpBlog

Wednesday, November 28, 2007

Using Code to show slowing down of sprites

Hi.

This is my first blog since June so i am not sure what is on here and isn't. So anyway sometime a couple of months ago i was making a movement system, one thing i couldn't do was check if the object was moving or not. I tryed a number of codes including the one i am about to give you. It didn't work. I spent days perfecting it so it would work.

I will explain everything after the code, please remember to not include the [code] and [/code] tags. as they will cause errors

[code]
//this was used for a car, if you need it for a human just add !keyboard_check_direct(vk_left) and (vk_right)
//Usuage: No arguments

if !keyboard_check_direct(vk_up) and !keyboard_check_direct(vk_down)
{
if speed>0
{
speed-=1
}
if speed<0
{
speed+=1
}
if
speed=0
{
speed=0
}
}


[/code]

What everything does?

The "if !keyboard_check_direct(vk_up) and !keyboard_check_direct(vk_down)" is asking if the keys on your keyboard are being pressed, if not (shown by the "!" being in front of the keyboard_key_press) the "if" will return true and execute the brackets below

The rest is simple, the speed<0>
else if the speed>0 then the speed will decrease by 1
and if the speed is 0 then is shall remain the same. YOU can add the image_speed or whatever else you want

Labels: