Make a character jump when click on a region (Resolved)

leogallardo

  • *
  • Posts: 28
Guys, I need your help, I have the following situation:
I need my character to jump whenever I touch everything except the top part of the screen (because that's where all the config buttons and the ads will go)

At first (when I didnt have the buttons), i did this, that worked like beautifully:


Then i decided to create a region for the "clickeable" area, and create and event that only worked on that particular region...


It seemed to work perfectly on paper, but in reality.. it doesn't...

The part of the jump works when I click for the first time
The part where it changes the variable, doesn't... until the 2nd click..
That's causing my character to double jump until it gets the "is_jumping" set to true


A link to the swf (I also attached it) http://www.swfcabin.com/open/1410065162

I'm also attaching the project file in case someone needs it.

The first actor (the one on the left) works well, but it still jumps if I click on the top of the screen.

The actor on the right double jumps and I have no idea why... My logic says that if the actor DOES jump, it should change the value of the variable... since they're inside the same IF statement, but they dont...

Please, help?

« Last Edit: October 06, 2014, 05:39:16 pm by leogallardo »

Basseman

  • Posts: 208
Where do you set the jumping to false again ?

Innes

  • *
  • Posts: 1960
Regions have their uses, but I try to avoid using them if possible, as I find other solutions more reliable and easier to manage.

The first screenshot  shows how to achieve the same goal without a region. Note in the screenshot, that I am testing for [y of mouse > 40]. You will need to change that to whatever y position is lower than your config buttons and ads.

When I tested the code as shown in the first screenshot, it still had the 'double-jump' bug. I think the reason for this is that when the [set main_character_jumping to true] is first executed, the actor is still touching the ground, so your 'resting' event (the one that switches the boolean back to false), immediately takes effect, meaning that when the actor first rises off the tiles, the boolean is still set to false, hence the double-jump is allowed. When the double-jump occurs, the actor is not touching the tiles, so the jumping boolean is set to true, thus preventing a triple-jump!

A workaround for this is to set the jumping boolean to true in a [do after] block as shown in the second screenshot.


Finally, I strongly advise using behaviors, rather than attaching events directly to actors and scenes. As soon as your game starts to get slightly complex, it becomes very difficult to manage directly attached events. You will also soon find that behaviors are far more flexible, making it far easier to manipulate the attributes of actors and scenes, than it is when they are directly attached.


The only time I would recommend directly attaching events to scenes / actors is when creating single, one-off events that do not have attributes.

« Last Edit: September 07, 2014, 03:10:35 am by Innes »
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

leogallardo

  • *
  • Posts: 28
Where do you set the jumping to false again ?

This is where the jumping status goes to false:


@Innes thank you so much, that worked :D
This is the final code for the jump:


My biggest fear about that code was the "y mouse" part, since I was doing the game for mobile devices, but it worked perfectly.

I still think that it's a bit odd that one code (the one in the "Always" event, actually changed the isJumping to true, while the event "Click" didn't. Like you explained, it makes a lot of sense that the actor was still touching the floor when I clicked, that's why it didn't change the value, but why the other event worked? Ahhh programming haha.

I'm slowly understanding how behaviors work, I have a few attached to other actors and scenes, but this is only a one character thing, I didn't think it'd be necessary to create a behavior for this one, although I will, just to start getting familiar with them :) Thanks for the advice.