Jump to content


Photo

Trying to not run in the air!


  • Please log in to reply
6 replies to this topic

#1 colinyoungblood

colinyoungblood

    GMC Member

  • New Member
  • 1 posts
  • Version:Mac

Posted 13 June 2012 - 12:59 AM

Hi all,
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!
  • 0

#2 smash ball

smash ball

    Volcanic Light

  • GMC Member
  • 1097 posts
  • Version:GM7

Posted 13 June 2012 - 01:01 AM

Are you using gravity or vspeed? If so, then you can check one of those before changing your sprite to the walking animation.
  • 1

#3 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 4689 posts
  • Version:GM8

Posted 13 June 2012 - 01:42 AM

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)

Edited by TheouAegis, 13 June 2012 - 01:42 AM.

  • 1

#4 integrate

integrate

    GMC Member

  • GMC Member
  • 255 posts
  • Version:GM8

Posted 13 June 2012 - 02:46 AM

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)

This is an interesting piece of code... I can't figure it out!

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.

  • 0

#5 TheouAegis

TheouAegis

    GMC Member

  • GMC Member
  • 4689 posts
  • Version:GM8

Posted 13 June 2012 - 02:55 AM

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==B) 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 ==

Edited by TheouAegis, 13 June 2012 - 02:57 AM.

  • 0

#6 integrate

integrate

    GMC Member

  • GMC Member
  • 255 posts
  • Version:GM8

Posted 13 June 2012 - 06:47 AM

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==B) 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 ==

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.
  • 0

#7 GMKn00b

GMKn00b

    GMC Member

  • GMC Member
  • 150 posts
  • Version:Unknown

Posted 13 June 2012 - 07:00 AM

Here's a youtube link I used for my platforming game :thumbsup:

http://www.youtube.c...h?v=ZsBBErKzGmg

Edited by GMKn00b, 13 June 2012 - 07:00 AM.

  • 1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users