[SOLVED] Using multiple virtual joysticks at the same time (multitouch)

I’ve been using the x-pressive analog joystick library:

http://developer.anscamobile.com/code/simple-analog-stick-joystick-module

And like the page says, it basically works right out of the box. However, although you can add more than one to the screen, you can only use one at a time.

I tried commenting out the “return true” line in the lib_analog_stick.lua file (line#157) but it didn’t make any difference.

I have a feeling I’m not the first person that’s tried to use two virtual joysticks simultaneously, although I didn’t see any other posts about this. Could anyone provide some insight?

Here’s the instantiation of the joysticks:
[lua]-- allow multi-touch
system.activate( “multitouch” )

– CREATE ANALOG STICKS
local StickLib = require(“lib_analog_stick”)
local stickLeft = StickLib.NewStick(
{
x = display.contentWidth*.2,
y = display.contentHeight*.85,
alpha = 0.3,
thumbSize = 16,
borderSize = 32,
snapBackSpeed = .2,
R = 255,
G = 255,
B = 255
} )

local stickRight = StickLib.NewStick(
{
x = display.contentWidth*.8,
y = display.contentHeight*.85,
alpha = 0.3,
thumbSize = 16,
borderSize = 32,
snapBackSpeed = .2,
R = 255,
G = 255,
B = 255
} )[/lua] [import]uid: 49447 topic_id: 16103 reply_id: 316103[/import]

I haven’t looked at that particular joystick stuff in ages, but at any point is it setting focus? That could be a contributor if so. [import]uid: 52491 topic_id: 16103 reply_id: 60015[/import]

thanks, got it. [import]uid: 49447 topic_id: 16103 reply_id: 60026[/import]

Producerism, I’m having the same problem, initially I thought it was because I was testing on a non-multi-touch supporting android device (xperia play), but the dragme multi-touch sample works fine.
can you share your solution? [import]uid: 11672 topic_id: 16103 reply_id: 67344[/import]

sure, should have posted it when I found the solution anyways.

in the [lua]Group.onDrag[/lua] function, add this to the “began” phase:
[lua]display.getCurrentStage():setFocus( T, event.id )[/lua]

and add this to the “ended”“cancelled” phase:
[lua]display.getCurrentStage():setFocus( nil, event.id )[/lua]

That should be it, those 2 lines. [import]uid: 49447 topic_id: 16103 reply_id: 67359[/import]

Perfect!
Thank you very much Producerism.
Greatly appreciated :slight_smile: [import]uid: 11672 topic_id: 16103 reply_id: 67453[/import]