Spawning Actors with Multitouch
K1dTrunks
PRO Posts: 55
Hey everybody, I could use some help with a simple multitouch system. All I want to do is this: whenever the player touches the screen, an actor is spawned at the touch location. There can be no more than 4 touches at any one time. I already have the following logic:
(in spawner actor)
When game.touches.count = 1
Spawn actor at game.touches.touch 1.X, game.touches.touch 1.Y
When game.touches.count = 2
Spawn actor at game.touches.touch 2.X, game.touches.touch 2.Y
When game.touches.count = 3
Spawn actor at game.touches.touch 3.X, game.touches.touch 3.Y
When game.touches.count = 4
Spawn actor at game.touches.touch 4.X, game.touches.touch 4.Y
This kinda works, except if I touch with more than one finger at the same time, it only spawns an actor at one of the touch points.
Also, if I touch 1 and then 2, then release 2 with 1 still on, an actor is spawned at 1 even though it already spawned one there when I first touched. I know this is because touches.count was 1 and then became 1 again when I released the second touch, so the rule is firing again, but I can't think of how to prevent this. I tried wrapping the four rules inside another rule that said "when touch is outside" but it didn't seem to make any difference. Any ideas?
(in spawner actor)
When game.touches.count = 1
Spawn actor at game.touches.touch 1.X, game.touches.touch 1.Y
When game.touches.count = 2
Spawn actor at game.touches.touch 2.X, game.touches.touch 2.Y
When game.touches.count = 3
Spawn actor at game.touches.touch 3.X, game.touches.touch 3.Y
When game.touches.count = 4
Spawn actor at game.touches.touch 4.X, game.touches.touch 4.Y
This kinda works, except if I touch with more than one finger at the same time, it only spawns an actor at one of the touch points.
Also, if I touch 1 and then 2, then release 2 with 1 still on, an actor is spawned at 1 even though it already spawned one there when I first touched. I know this is because touches.count was 1 and then became 1 again when I released the second touch, so the rule is firing again, but I can't think of how to prevent this. I tried wrapping the four rules inside another rule that said "when touch is outside" but it didn't seem to make any difference. Any ideas?
Comments
I would think that once you get the logic behind how to get multitouch properly working, you may have a better time figuring it out.
Do you have to spawn the actors, or could they be off the screen? You could assign each one a specific finger to snap to, and when that touch becomes active, it snaps to that touch. When that touch is gone, then simply have the actor snap back off the screen. Just a thought, not at my computer to test it out at the moment.
Currently my multitouch programming is 5 actors parked off screen, each one is constrained to a different device.touch.x/y. They pop on screen when that touch# is active and back off screen when that touch is released.
I learned to do it from the "spare code" thread ( @POM THANK YOU!! )
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS