Toggle between Player Global Movement Vs. Specific Targeted location
I have a character called "player" which moves with proper animation to a mouse touch on the X axis which I think works brilliantly. If the user touches in front of the player while it is moving the player goes to the new selected position, and if the user touches behind where the player is moving the player instantly turns and goes to the new touch spot. Works great I call it "globalMovement". I even have the idle set up so that the character will face the mouse cursor position, but that really won't be necessary on a touch screen device.
Here is the player setUp. It has 3 attributes ("targetX" and "mySpeed" both real and "moving" which is a boolean)
rule:
When: mouseButton is down
Cha.Att:self.targetX to mouse.positionX
Cha.Att:self.moving to true
Cha.Att:self.mySpeed to abs(self.targetX-self.position.X)/2
rule:
When:self.moving is true
moveTo: position self.targetX and 226(thats just where I have him hanging)
Speed: mySpeed
rule:
When: att:self.targetX > or = to self.position.X
Animate_moving right
rule:
When: att:self.targetX < or = to self.position.X
Animate_moving left
rule:
When:Att:self.targetX = self.position.X
cha.Att: self.moving to false
otherwise
[moderator note - does the rule below go inside of the otherwise right above here?]
rule:
When:game.mouse.position.X > or = to self.position.X
and
Att: self.moving is false
Animate_idle facing right
otherwise
Animate_idle facing left
I now would like the player to interact with other graphic items on the stage. Basically when this new item is clicked the player moves to a designated spot (say 200 on the Y axis or Y position of the item ) and then goes through an animated sequence to completion. During this move-to-and-animate sequence I would like to shut off the "globalMovement" so as not to interfere with the operation, and then turn "globalMovement" back on when it is complete.
So I set it up like this
In the game attributes I made a new boolean called "moveToClick"
Then in the clickable graphic I set up...
rule:
When:actor receives:touch is inside
Cha.Att:moveToClick is true</code.
Back in the player I setUp...
rule:
When Att:game.moveToClick is true
moveTo:position 620 and 226
Speed:mySpeed
Animate:move left
rule:
When:Att:self.position.X is< or =620
Animate:move right
rule:
When:self.position.X = 620
Animate_idle
cha.att:self.moving to false
cha.att:moveToClick to false
So some where I'm screwed up I need to use the Att:moveToClick maybe to shut off the "globalMovement" or ???
Any help would be gratefully appreciated, I 've been stuck on this way too long. Thanks
Comments
I'm going to see if I can clean your post up a bit with some < code > and < / code > tags. The forums formatting options leave a lot to be desired!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
It sounds like everything in the first section of your rules (that determine normal movement) needs to go inside of a rule with the condition When attribute game.moveToClick is false.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thanks! Yeah, I've almost got it working now the way I want it to. I'd love to share it and see what others might say about the way it's set up. But it takes me so long to type all the code out. I will have to look into a web hosting site for linking to the threads. Any you might recommend ?
Dropbox or MediaFire are popular ones.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User