Virtual Joystick Module For Games

Hi Rob.  This code seems to have gone missing.  Any idea where we can get it now?

Thats a link to our very old community code system.  Most of that code is old G1 code, or the developers are not maintaining it etc.  We had that up quite a while to give people time to move things.

I think this is the module.  I actually used it in one of my games.   This is the version in my downloads folder, so it should be the original file.  I know I had to make some changes in my game to implement it, and I wouldn’t want to share the hacked version.

module(..., package.seeall); function joystick:create(group, imgJoystick, joyWidth, joyHeight, imgBgJoystick, bgWidth, bgHeight) &nbsp;&nbsp; &nbsp;local stage = display.getCurrentStage(); &nbsp;&nbsp; &nbsp;local mMin = math.min; &nbsp;&nbsp; &nbsp;local mCos = math.cos; &nbsp;&nbsp; &nbsp;local mSin = math.sin; &nbsp;&nbsp; &nbsp;local mAtan2 = math.atan2; &nbsp;&nbsp; &nbsp;local mSqrt = math.sqrt; &nbsp;&nbsp; &nbsp;local mFloor = math.floor; &nbsp;&nbsp; &nbsp;local mPi = math.pi; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;local joyGroup = display.newGroup(); &nbsp;&nbsp; &nbsp;group:insert(joyGroup); &nbsp;&nbsp; &nbsp;local bgJoystick = display.newImageRect(joyGroup, imgBgJoystick, bgWidth, bgHeight ); &nbsp;&nbsp; &nbsp;bgJoystick.x, bgJoystick.y = 0, 0; &nbsp;&nbsp; &nbsp;local radius = bgJoystick.contentWidth/4; &nbsp;&nbsp; &nbsp;joyGroup.radius = radius; &nbsp;&nbsp; &nbsp;local radToDeg = 180/mPi; &nbsp;&nbsp; &nbsp;local degToRad = mPi/180; &nbsp;&nbsp; &nbsp;local joystick = display.newImageRect(joyGroup, imgJoystick, joyWidth, joyHeight ); &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;function joystick:touch(event) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local phase = event.phase; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if phase == "moved" then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if self.isFocus then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local parent = self.parent; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local posX, posY = parent:contentToLocal(event.x, event.y); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local angle = (mAtan2( posX, posY )\*radToDeg)-90; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if angle \< 0 then angle = 360 + angle end; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local distance = mSqrt((posX\*posX)+(posY\*posY)); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if distance \>= radius then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local radAngle = angle\*degToRad; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;distance = radius; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.x, self.y = distance\*mCos(radAngle), -distance\*mSin(radAngle) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.x, self.y = posX, posY; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;parent.angle = angle; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;parent.distance = distance; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;stage:setFocus(event.target, event.id); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.isFocus = true; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.parent.state = true; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.alpha = 0.5;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;elseif phase == "began" then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;stage:setFocus(event.target, event.id); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.isFocus = true; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.parent.state = true; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.alpha = 0.5; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local parent = self.parent; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local posX, posY = parent:contentToLocal(event.x, event.y); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.x, self.y = posX, posY; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local angle = (mAtan2( posX, posY )\*radToDeg)-90; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if angle \< 0 then angle = 360 + angle end; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local distance = mSqrt((posX\*posX)+(posY\*posY)); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if distance \>= radius then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local radAngle = angle\*degToRad; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;distance = radius; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.x, self.y = distance\*mCos(radAngle), -distance\*mSin(radAngle) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.x, self.y = posX, posY; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;parent.angle = angle; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;parent.distance = distance; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.isFocus = false; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.parent.state = false; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.x, self.y = 0, 0; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.parent.distance = 0; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.parent.angle = 0; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;stage:setFocus(nil, event.id); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.alpha = 1; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return true; &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;joyGroup.activate = function() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;joyGroup[1]:addEventListener("touch", joyGroup[2]); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;joyGroup.angle, joyGroup.distance = 0, 0; &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;joyGroup.deactivate = function() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;joyGroup[1]:removeEventListener("touch", joyGroup[2]); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;joyGroup.angle, joyGroup.distance = 0, 0; &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;joyGroup.x, joyGroup.y = joyGroup.contentWidth\*0.5, display.contentHeight-joyGroup.contentHeight\*0.5; &nbsp;&nbsp; &nbsp;return (joyGroup); end &nbsp;

Rob

Thanks a lot, Rob.  Alex also found a copy in a different thread and sent a link.  It is slightly different from what you posted, but accomplishes the same thing.  I have it working in my code now and am tweaking it for my own purposes.  Really helpful code.

I’ve used Matt Pringle’s joystick code before, but now after 2.0 it doesn’t seem to work - still scratching my head, but I’m sure at some point I’ll give up :slight_smile:

Hi Rob.  This code seems to have gone missing.  Any idea where we can get it now?

Thats a link to our very old community code system.  Most of that code is old G1 code, or the developers are not maintaining it etc.  We had that up quite a while to give people time to move things.

I think this is the module.  I actually used it in one of my games.   This is the version in my downloads folder, so it should be the original file.  I know I had to make some changes in my game to implement it, and I wouldn’t want to share the hacked version.

module(..., package.seeall); function joystick:create(group, imgJoystick, joyWidth, joyHeight, imgBgJoystick, bgWidth, bgHeight) &nbsp;&nbsp; &nbsp;local stage = display.getCurrentStage(); &nbsp;&nbsp; &nbsp;local mMin = math.min; &nbsp;&nbsp; &nbsp;local mCos = math.cos; &nbsp;&nbsp; &nbsp;local mSin = math.sin; &nbsp;&nbsp; &nbsp;local mAtan2 = math.atan2; &nbsp;&nbsp; &nbsp;local mSqrt = math.sqrt; &nbsp;&nbsp; &nbsp;local mFloor = math.floor; &nbsp;&nbsp; &nbsp;local mPi = math.pi; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;local joyGroup = display.newGroup(); &nbsp;&nbsp; &nbsp;group:insert(joyGroup); &nbsp;&nbsp; &nbsp;local bgJoystick = display.newImageRect(joyGroup, imgBgJoystick, bgWidth, bgHeight ); &nbsp;&nbsp; &nbsp;bgJoystick.x, bgJoystick.y = 0, 0; &nbsp;&nbsp; &nbsp;local radius = bgJoystick.contentWidth/4; &nbsp;&nbsp; &nbsp;joyGroup.radius = radius; &nbsp;&nbsp; &nbsp;local radToDeg = 180/mPi; &nbsp;&nbsp; &nbsp;local degToRad = mPi/180; &nbsp;&nbsp; &nbsp;local joystick = display.newImageRect(joyGroup, imgJoystick, joyWidth, joyHeight ); &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;function joystick:touch(event) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local phase = event.phase; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if phase == "moved" then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if self.isFocus then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local parent = self.parent; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local posX, posY = parent:contentToLocal(event.x, event.y); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local angle = (mAtan2( posX, posY )\*radToDeg)-90; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if angle \< 0 then angle = 360 + angle end; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local distance = mSqrt((posX\*posX)+(posY\*posY)); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if distance \>= radius then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local radAngle = angle\*degToRad; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;distance = radius; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.x, self.y = distance\*mCos(radAngle), -distance\*mSin(radAngle) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.x, self.y = posX, posY; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;parent.angle = angle; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;parent.distance = distance; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;stage:setFocus(event.target, event.id); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.isFocus = true; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.parent.state = true; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.alpha = 0.5;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;elseif phase == "began" then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;stage:setFocus(event.target, event.id); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.isFocus = true; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.parent.state = true; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.alpha = 0.5; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local parent = self.parent; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local posX, posY = parent:contentToLocal(event.x, event.y); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.x, self.y = posX, posY; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local angle = (mAtan2( posX, posY )\*radToDeg)-90; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if angle \< 0 then angle = 360 + angle end; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local distance = mSqrt((posX\*posX)+(posY\*posY)); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if distance \>= radius then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local radAngle = angle\*degToRad; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;distance = radius; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.x, self.y = distance\*mCos(radAngle), -distance\*mSin(radAngle) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.x, self.y = posX, posY; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;parent.angle = angle; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;parent.distance = distance; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.isFocus = false; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.parent.state = false; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.x, self.y = 0, 0; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.parent.distance = 0; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.parent.angle = 0; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;stage:setFocus(nil, event.id); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;self.alpha = 1; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return true; &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;joyGroup.activate = function() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;joyGroup[1]:addEventListener("touch", joyGroup[2]); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;joyGroup.angle, joyGroup.distance = 0, 0; &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;joyGroup.deactivate = function() &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;joyGroup[1]:removeEventListener("touch", joyGroup[2]); &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;joyGroup.angle, joyGroup.distance = 0, 0; &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;joyGroup.x, joyGroup.y = joyGroup.contentWidth\*0.5, display.contentHeight-joyGroup.contentHeight\*0.5; &nbsp;&nbsp; &nbsp;return (joyGroup); end &nbsp;

Rob

Thanks a lot, Rob.  Alex also found a copy in a different thread and sent a link.  It is slightly different from what you posted, but accomplishes the same thing.  I have it working in my code now and am tweaking it for my own purposes.  Really helpful code.

Sorry cannot believe I am stuck on this but I cant seem to link the simplejoystick.lua (Rob’s simple module) to the object that I want to move. I have activated the module and created the joystick js:activate() but how do I link the joystick to a function to move an object?

I tried using roaming gamers joystick in the ssk but I cannot seem to get it activated at all. Don’t think I have the requires in the correct places.

This would make a decent community-sourced Lua plugin that someone could distribute for free in our store. :wink:

Well it’s not *my* joystick.  I just made sure it survived getting to the new community code base.

Rob

Could someone explain what LairdGames meant by using a “soft filter”. I’m interested because I am creating a prototype just using a white box that responds to the virtual joystick and it seems to flicker alot when moving across the screen…Could this maybe be caused because I’m using a white box and not a regular png?

Sorry cannot believe I am stuck on this but I cant seem to link the simplejoystick.lua (Rob’s simple module) to the object that I want to move. I have activated the module and created the joystick js:activate() but how do I link the joystick to a function to move an object?

I tried using roaming gamers joystick in the ssk but I cannot seem to get it activated at all. Don’t think I have the requires in the correct places.

This would make a decent community-sourced Lua plugin that someone could distribute for free in our store. :wink:

Well it’s not *my* joystick.  I just made sure it survived getting to the new community code base.

Rob

Could someone explain what LairdGames meant by using a “soft filter”. I’m interested because I am creating a prototype just using a white box that responds to the virtual joystick and it seems to flicker alot when moving across the screen…Could this maybe be caused because I’m using a white box and not a regular png?