make player jump if you touch anywhere on screen EXCEPT in certain areas
![developer6810](http://forums.gamesalad.com/applications/dashboard/design/images/defaulticon.png)
I got all the coding working good except there are three buttons -- two action buttons and a pause button. If I tap any of those, it makes the player jump as well as do the button's action. Here's my coding:
______________________________
RULE: attribute (game.jumps) > 0 AND attribute (game.Touches.Count) > 0
change attribute (game.jumps) to (game.jumps-1) AND
change attribute (self.Motion.LinearVelocityY) to 525
______________________________
How would I change that to incorporate the position of the buttons?
Thanks!
______________________________
RULE: attribute (game.jumps) > 0 AND attribute (game.Touches.Count) > 0
change attribute (game.jumps) to (game.jumps-1) AND
change attribute (self.Motion.LinearVelocityY) to 525
______________________________
How would I change that to incorporate the position of the buttons?
Thanks!
Best Answer
-
guilleface Posts: 1,014
how about when touches count>0 and "don't jump" is false
create a global attribute "don't jump" and in your 3 other buttons when press change
"don't jump" to true
Answers
Thanks
I tried that and since you would have to change it back eventually, I added a timer that said when don't jump is true, after 0.1 seconds, change it to false and when you hit one of the 3 buttons it still jumped. Any ideas?
Another solution could be to add a rule to the jump button actor that says X and Y of the touch location are not inside of the position of the buttons.
The layer one didn't work, but how exactly would you add the condition of the X and Y positions (sorry I'm get confused with this kind of stuff)?
@developer6810
You'd have to find all the coordinates - top-left & right, bottom left & right – for all those certain areas where jumping isn't possible; quite a lot of work then to put it into your Rules as conditions.
Another way to tackle your problem which would be easier I'm thinking, is to make up your areas where your actor CAN jump as a transparent patchwork, so leaving "holes" where the player can't jump, the jump rules just in the patchwork actors.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Thanks, I tried your second idea, using the invisible actors and using the same rules as the my old scene and it wouldn't let me jump at all. I was wondering exactly how you would for the first idea, after you calculate all the coordinates put it in conditions, like could you give me an example using random coordinates because I can't figure out how to do it. Thanks!
Yeah, I just calculated all the coordinates, not that much work, just simple math
@developer6810
It really would be a lot of work for you using the coordinates method, I think, plus it'd be more work if you wanted to change them.
So going back to the "patchwork" idea, a few more details then (one way to work it): make a boolean called JumpArea. Then in every single invisible actor that's making up this patchwork, you'll need to put a Rule:
When Actor overlaps or collides with actor (your actor that jumps)
Change Attribute JumpArea to true
otherwise
Change Attribute JumpArea to false
Then in your jump button add before the jump rules:
When JumpArea is true
Hope that works out for you.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Yeah, it still jumps when I click the buttons.
If you did it as I explained, it should work fine... remember that with this method, the boolean JumpArea will only turn to false when the actor that jumps is totally outside any jump area, so you might need to make allowances for this, and adjust the sizes of the jump areas.
A suggestion: while you're working on these jump areas, don't make them transparent temporarily, that way you can see more what's going on to check if it's working as you want.
Edit: "...when I click the buttons." Plural? OK, if more than one button is used for the jumping, make sure When JumpArea is true is added to both buttons.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Wait if I did that then you wouldn't be able to touch anywhere to jump cause my game is an infinite runner game so he stays in the same place (on the bottom left side of the screen) the entire time while the buttons are two on the bottom right and one on the top right? Sorry I'm just getting a little confused.
Let's say your button is 30 pixels wide and 30 pixels high. If it occupies an X value of 10-40 and a Y value of 10-40 (yes, a simplistic example, but you should get the idea), then your rule would just have to check for touch is pressed + the x and y values not falling in the range of the button.
I don't think this would be difficult to implement; however, @gyroscope has an even easier way to do it.
Yeah I've been trying his idea but I think I'm doing something wrong that I don't know of. However, I already got all the coordinates and stuff so following that rule if touch is pressed + the x and y values not falling in the range what behavior and what coding in it would I use for the "the x and y values not falling in the range of the button?" Sorry, I'm confused
That's what gyroscope was trying to help me with but I didn't get it to work. I'm willing to take a lot of effort doing your previous idea so back to my original question, what behavior and what coding in it would I use for the "the x and y values not falling in the range of the button" part of the jump rule?
Thanks!
@developer6810
I didn't realise it was an infinite runner-type game....the solution I suggested was for a static background.
So off the top of my head, what might work here in that situation: you're going to have to spawn invisible blocks which are constrained with the moving background, with the rules that if your jumping player collides with it, it'll jump back. And seeing as these invisible blocks will be just above the head of the jumping player, it should stop it from jumping....
That explanation all sounds a bit clumsy but there might be some mileage there....
Anyhow, maybe reconsider limiting your jumping player altogether; and allow him to jump wherever it wants... if it's just a refinement and not actually part of the gameplay then just ditch the idea... it'd sure make life easier for you....
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps