Disable touch input until sprite reaches tapped target.
dalbelo
Member Posts: 6
I have a 5 x 8 grid and I have figured out how to get a sprite to move, down, left and right while preventing diagonal movement by touching a neighboring grid square. I have even sorted out how to limit the travel to one grid square at a time. The problem I am having now is, if I tap (grid 1) and then immediately tap a neighbor of (grid 1) (above, below, or the opposite side from the sprite,) the sprite takes off in that direction along the same axis or diagonally which causes it to bypass (grid 1). What I would like to do is prevent any touch input until the sprite has reached the target and then enable touch input for movement to the next grid. I can get the touch input to stop by changing a game level attribute to CanTouch = 0, but I can't figure out a trigger to set it back to CanTouch = 1.
Here is a simplified version the logic:
Game Level Attributes:
CanTouch = 0 boolean
XPosition = 0 real
YPosition = 0 real
MoveToTarget = 0 boolean
(GRID SQUARE LOGIC)
WHEN ALL:
touch is: [inside]
if [game.CanTouch] is true
DO:
SET: [game.XPosition] TO: [self.position.x]
SET: [game.YPosition] TO: [self.position.y]
SET: [CanTouch] TO: [0] (Prevents grids from responding to screen touch.)
SET: [game.MoveToTarget] TO: [1] (Triggers sprite to move to X or Y position.)
(SPRITE LOGIC)
WHEN ALL:
if [game.MoveToTarget] is true
DO:
MOVE TO: [game.XPosition], [gameYPosition] relative: scene
@ [300] RTC
------------------------------------------------
After the sprite reaches the target grid square, I need to set game.CanTouch to 1, which will allow the grid squares to respond to input again.
Any assistance is greatly appreciated.
Here is a simplified version the logic:
Game Level Attributes:
CanTouch = 0 boolean
XPosition = 0 real
YPosition = 0 real
MoveToTarget = 0 boolean
(GRID SQUARE LOGIC)
WHEN ALL:
touch is: [inside]
if [game.CanTouch] is true
DO:
SET: [game.XPosition] TO: [self.position.x]
SET: [game.YPosition] TO: [self.position.y]
SET: [CanTouch] TO: [0] (Prevents grids from responding to screen touch.)
SET: [game.MoveToTarget] TO: [1] (Triggers sprite to move to X or Y position.)
(SPRITE LOGIC)
WHEN ALL:
if [game.MoveToTarget] is true
DO:
MOVE TO: [game.XPosition], [gameYPosition] relative: scene
@ [300] RTC
------------------------------------------------
After the sprite reaches the target grid square, I need to set game.CanTouch to 1, which will allow the grid squares to respond to input again.
Any assistance is greatly appreciated.
Comments
Change attribute: CanTouch to 1
Is what I'm getting from this.
Of course, move to might not be horribly exact, so instead of making the above rule equal to, you might want to set it to a range of a few pixels.
Thanks
So in total you would have four:
When attribute self.PositionX > game.Xposistion-1 AND When attribute self. PosistionX <game.xposistion +1
Do the same for the Y value. You might want to change the 1 to give you more wiggle room.
If that doesn't help, I'm not sure what will.
IF: self.motion.linear Velocity x/y = 0
DO:
SET: game.CanTouch TO: 1
This seems to be working so far, but I am still testing.
Once again, thanks for the suggestion.