Spawning Actors with Multitouch

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?





Comments

  • JarrenHJarrenH Member Posts: 206
    Multitouch is a tricky thing in gamesalad, take it from the guy who's first game involves up to 5 fingers on the screen at once. :P have you seen @fryingbaconstudios wonderful multitouch tutorials?



    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.
  • K1dTrunksK1dTrunks PRO Posts: 55
    I have watched the tutorials, and they are great, but I'm still not sure how to get it to spawn an actor at all touch points when pressed at the same time.
  • JarrenHJarrenH Member Posts: 206
    edited June 2013
    I think the reason it's not working, is that when you touch multiple fingers at once, the spanner actor automatically sees 3 or 4 fingers on the screen, so only that rule fires. And you are right, as soon as you lift a finger, the rules will fire again...

    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.
  • grimtoothgrimtooth Member Posts: 69
    edited June 2013
    I agree with @JarrenH

    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!! )
  • K1dTrunksK1dTrunks PRO Posts: 55
    Thanks guys, maybe I'll try something like that. I'd still prefer to use spawning if possible though, so if anyone can think of a good system, please share!
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited June 2013
    Okay some words from the multi touch Jedi..lol if you watched the videos you'd have seen this issue coming. Watch the first one again about the touch count vs touches. You will never be able to do it based on the touch count. What you need to do is build a system that keeps track of what touch is on the screen as I said in my video. And just a note: there is no simple multitouch system over two touches. This is one of the hardest type of coding to do with GS. The reason why your touch is outside didn't work is because based on the touch count as the trigger.
Sign In or Register to comment.