Please Help Me
boberto
Member Posts: 35
SO I have a game, and I want it to work like this:
When the screen is tapped, the character goes right, but the next time it is tapped, the character goes left, and that repeats over and over.
How do I do this? Thanks.
Comments
First off I have to say that I'm not an expert but my first thought when I read your question was to make a integer attribute. +1 every time you tap the screen. Then right when attribute is equal to 1 and left when it's equal to 2. You'll also need reset the count when attribute is equal to 2 and tap is released.
A theory that might work Sorry if my english is sub-par.
Make rule for your actor that says . . .
When mouse button is down
Change Linear Velocity X to -Linear Velocity X
Also set an initial Linear Velocity X value in the actor's attributes.
Thank you, and no, your english is great
I will try it.
But then the actor never stay still right?
Will the mouse button action work for tapping too?
Ah! I just re-read the OP, I thought that's what he wanted, you tap to change direction, but I suspect I'm wrong and I think you are right, he only wants it to move when you tap the screen . . . . !
If he wants the actor to stop moving, then he will need to say how long it moves for or under what conditions it stops and so on.
If he wants the actor to move only while the screen is touched then you just need to change the 'button down' condition in my example to 'touch is pressed'.
Sorry for my unclear question. I want to do what socks thought, my character is always moving forward, but you tap to change direction. How do I do this?
So I tried it, @socks, but it just goes left very time. How do I make it switch off directions?
Can you post a screenshot of your rules . . . .
Maybe something like this would work.
create a global attribute called direction type integer
make a rule
when device touch counter = 1
change attribute game.direction to mod((game.direction+1),2)
Inside moving actor
make a rule
if game.direction = 0
change linear velocity X to 200
otherwise
change linear velocity X to -200
Thank you. I've tried a lot of functions like that, but they all go like this:
I click once and the actor turns right
I click again and the actor left
I click again and nothing happens.
@socks yes I will
Ok so here is my full writeup, with updates from some of the comments:
My character is in a landscape iphone game with no gravity. It has a behavior that says go up at a speed of 150. I have the rotation constrained to my game.direction attribute. How do I get so that when the background is tapped, the game.direction will change each time (for example, first tap changes it to 10, second tap back to 0)
I hope it makes more sense now. Thanks.
Change x to 10-x
When touch is pressed do change attribute game.LeftandRight to (game.LeftandRight+1)%2
I would suggest putting it in a rule like
When game.StartGame = 1 or is true (depending on if you used a integer or boolean)
and when touch is pressed
Do:
change attribute game.LeftandRight to (game.LeftandRight+1)%2
Set it up in how the main actor moves like
when game.LeftandRight = 0 do Move right
else:
move left
If you don't have it solved I'll try to make a quick template
Make your actor do this....by default I assume your actor is facing right.....make two Boolean attributes (game level) called left and right.
Now in your actor make a rule
"when right is true, move 0* @ speed 100
Make another
"When left is true, move 180* @ speed 100
Now make another rule when touched is pressed and right is true change actor attribute flip horizontal and make left true and right false...then in otherwise make it when touch is pressed and left is true, flip horizontal and make left false and right true.
Complete Guide to iOS Publishing {} Complete Guide to Mac Publishing
Thank you. I actually tried that exact same thing, but I will try it again.
@jamie_c has a few tutorials and templates I think that are free that explain this in great detail.
Complete Guide to iOS Publishing {} Complete Guide to Mac Publishing
Is there a loop function? Like once everything inside it is done, it runs again?
//
what
Please do!
I made a post, but decided to remove it as it probably wasn't that helpful.
OK
I should add you need to start with right true or left true. One of the has to be true first at start. By default they both would be false. I put that at the top of my logic tree.
Complete Guide to iOS Publishing {} Complete Guide to Mac Publishing
Just divide the screen into to buttons with appropriate attribute. And set a Y velocity to the actor.
My first game Extreme Highway Challenge works exactly like that.
This thread is way out of control..lol
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
Okay, I know I can do that.
Good news! I figured it out!