While frequenting the GameSalad forums, I spotted an interesting thread. Apparently, the default template for creating dual controllers is a bit buggy. I know the frustration that this can cause, as my first GameSalad project didn’t go so smoothly. The virtual joysticks would jam, creating a rather broken gaming experience. Fortunately, I designed my own system to resolve this problem. A free template is available for download.
I originally published the system in The Unofficial GameSalad Textbook. However, I’ve been thinking about the creation of a second edition — a PDF with embedded templates as examples. This post is a bit of an experiment in creating those useful files.
So, here’s how my control system works. Instead of using invisible sensor actors to locate the touch points, I use nested rules and a single joystick actor. When that actor is touched, the rules are used to determine which point is being used. How exactly is that achieved? It’s by determining the position of a touch point. When a touch point is not in use, it simply defaults to X=0 & Y=0. Knowing this, I can use greater than and less than conditions to isolate the touch points.
If a touch is greater than zero, then the touch is in use!
The controller base takes up space on the screen. That’s where the rules go to work. If the touch is in the actor’s square, then that’s the touch data to be used. Since nested rules are being used, there can’t be any jamming.
- If touch #1 is in the square, then use touch #1 location data
- Otherwise, if touch #2 is in the square, then use touch #2 location data
- Otherwise, if touch #3 is in the square, then use touch #3 location data
- Otherwise, if touch #4 is in the square, then use touch #4 location data
- Otherwise, if touch #5 is in the square, then use touch #5 location data
That takes care of all five touch points for iPhone and iPod Touch devices. For iPad, there are 11 touch points. (That’s where a big monitor is handy.) Instead of explaining this further, I posted the template for download.
So, if you’re following along, you might have some questions. How is a round controller disc going to work right in a square box? It works by using a round collision shape for the controller actor. That way, the actor only runs the rules when touched. Even though the greater than and less than conditions create a square, they’re all in a giant rule that essentially says — only run this when touched.
You might also be wondering, “Can I change the size and position of the actor?” That’s what’s great about this template. I updated it to be more dynamic. If you look at the rule conditions in the template, I’m using expressions…
- If game.touches.touch 1.X < self.Position.X + ( self.Size.Width /2)
- and game.touches.touch 1.X > self.Position.X – ( self.Size.Width /2)
- and game.touches.touch 1.Y < self.Position.Y + ( self.Size.Height /2)
- and game.touches.touch 1.Y < self.Position.Y – ( self.Size.Height /2)
By using the actor’s width and height data, the rules will still work even if the actor is resized.
Another big question, “Where’s the thumbstick?” If you want to maintain the single actor, they can be displayed with particles. A second actor could be added, which would be constrained to the active touch point. But generally, I don’t even use a thumbstick. I don’t really see the need. REAL THUMBS WOULD COVER THEM UP!