How to make a button make an actor jump?

PurulentSoftwarePurulentSoftware Member Posts: 15
edited November -1 in Working with GS (Mac)
Hello
Does anyone know how to make a button control a character. I already have the stuff set up to make my actor jump... The only problem is i cant figure out how to make the button send the message to the actor to jump? I know i can probably use a bool but is there an easier way?

Comments

  • rebumprebump Member Posts: 1,058
    Not on a Mac right now but you will need to add your "jump code/routine" to a rule that is fired upon an event (the on a keryboard key pressed/down event and select the key to use..."j" or the "up arrow"). Pretty simple, just poke around in the rule conditions...the default one that is present when you add the rule is the type to use (the "attribute" type is the other one and that is NOT the one to use).
  • PurulentSoftwarePurulentSoftware Member Posts: 15
    Sorry I wasn't specific enough, I want it to work for a button that is displayed on the screen.
    Thanks
  • rebumprebump Member Posts: 1,058
    Ahh. I see. Similar...an actor rule with a touch event "inside" although there is debate on whether or not the rule needs an additional condition of a touch "pressed" event too. In my trials, if I just had touch "pressed", a touch anywhere on the screen got fired. Then I added an additional touch "insised" test and it worked only on, err, in the actor's screen presence. Never really tested by removing the "pressed"...so maybe that is where the debate lies and maybe the "pressed" is indeed not needed. :-P

    So the actor (the button) sensing the press would set a game boolean attribute to "true" (i.e. call it "PlayerJumping"). Then the player actor could have a rule that if "PlayerJumping" is true, do the jump code/routine and then set "PlayerJumping" to false to signal jump complete.

    This would need to be played with if you add a super-jump or something (i.e. press jump again at the top of the jump for extra height).
  • micahmicah Member Posts: 85
    You have to use a bool game attribute. It's annoying at first, but it's really not that bad.

    Your button actor sets game.up_pressed to 1 when pressed, otherwise it sets game.up_pressed to 0. Your player has a rule that jumps when game.up_pressed is true.

    The nice thing about doing it this way is then you can have multiple ways of sending the up_pressed signal to the player. You can make it so when you press the up key on the keyboard it sets game.up_pressed to 1, or when the user touches an onscreen button. This way the same game can work for iPhone and for web without having to edit the actors around much.
  • PurulentSoftwarePurulentSoftware Member Posts: 15
    But won't that tell the button to jump and not my character? See i just want a round button in the corner of my screen that when someone presses it my actor jumps.
  • micahmicah Member Posts: 85
    No no, all the button does is change game.up_pressed attribute, nothing else. The player has the rule that jumps if game.up_pressed is true.
  • rebumprebump Member Posts: 1,058
    You may have read my post when I pre-maturely hit Send. Looks like micah was typing in something similar at the same time. Re-read the prior two posts.
Sign In or Register to comment.