Trying to not run in the air!
#1
Posted 13 June 2012 - 12:59 AM
thank you in advance,
I am pretty new to Game Maker, am using it on a Mac, and am using the drag and drop functions.
I was and I guess am, making a little platformer and was having a small problem.
My character uses 4 sprites:
Walk Right
Walk Left
Jump Right
Jump Left
The walking ones have animations. When I jump from standing still it changes to the jumping sprite, but when I jump while running it plays the walking animation still, instead of jumping through the air like I want him to. I have tried a couple of things but to no avail. Any help would be greatly appreciated.
Thanks!
#2
Posted 13 June 2012 - 01:01 AM
#3
Posted 13 June 2012 - 01:42 AM
Edited by TheouAegis, 13 June 2012 - 01:42 AM.
#4
Posted 13 June 2012 - 02:46 AM
This is an interesting piece of code... I can't figure it out!if place_free(x,y+1) sprite_index=jump_left * (sprite_index==walk_left || sprite_index==jump_left) + jump_right * (sprite_index==walk_right || sprite_index==jump_right)
What does multiplying sprite_indexes accomplish? This throws me off:
sprite_index=jump_left multiplied by either sprite_index==walk_left OR sprite_index == jump_left ??
Would you mind providing a small explanation of this? I want to learn something new.
Edited by integrate, 13 June 2012 - 06:49 AM.
#5
Posted 13 June 2012 - 02:55 AM
a==b is a algorithmic function. In other words, it returns a value. If it's false, it returns 0, otherwise it returns 1. So x*(a==
Anyway, the formula I wrote basically says
F(sprite_index) = jump_left * a + jump_right * b
a = sprite_index==walk_left||sprite_index==jump_left
b = sprite_index==walk_right||sprite_index==jump_right
So if the player sprite is walk_left, then a is true and b is false. Therefore
F(sprite_index) = jump_left * 1 + jump_right * 0
F(sprite_index) = jump_left
This is also why it is very important to not use = in place of ==
Edited by TheouAegis, 13 June 2012 - 02:57 AM.
#6
Posted 13 June 2012 - 06:47 AM
That is awkward. Thank you for that explanation, I believe I understand it now. Though, I see myself writing it out in long-hand simply for readability. It's quite a shortcut, indeed. Just not used to seeing syntax like that.I brought this up in a thread once. Either nocturne or torigara explained why it worked (or should work) to me.
a==b is a algorithmic function. In other words, it returns a value. If it's false, it returns 0, otherwise it returns 1. So x*(a==will return x if a does equal b or 0 if a does not equal b. >, <, ==, and != all have higher arithmetic priority than &&, || and ^^, that's why you can type if sprite_index==walk_left||sprite_index==jump_left for example.
Anyway, the formula I wrote basically says
F(sprite_index) = jump_left * a + jump_right * b
a = sprite_index==walk_left||sprite_index==jump_left
b = sprite_index==walk_right||sprite_index==jump_right
So if the player sprite is walk_left, then a is true and b is false. Therefore
F(sprite_index) = jump_left * 1 + jump_right * 0
F(sprite_index) = jump_left
This is also why it is very important to not use = in place of ==
#7
Posted 13 June 2012 - 07:00 AM
http://www.youtube.c...h?v=ZsBBErKzGmg
Edited by GMKn00b, 13 June 2012 - 07:00 AM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











