Link to full example:
http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/04/joystick.zip
Video of example:
https://www.youtube.com/watch?v=TM3Z_8w1cd0&feature=youtu.be
Pertinent code:
io.output():setvbuf("no") display.setStatusBar(display.HiddenStatusBar) require "ssk.loadSSK" -- 1. Always use groups to contain objects local group = display.newGroup() -- 2. Let's make a background -- centerX, centerY, fullw, fullh - All globals from SSK local back = display.newRect( group, centerX, centerY, fullw, fullh ) back:setFillColor( unpack(\_CYAN\_) ) -- \_CYAN\_ from SSK back.alpha = 0.10 -- 3. It is NOT suggested that you use the joystick code directly. -- Use the oneStick easy input instead. That is why I wrote the easy input helpers. :) -- Yes, I know this stuff is not well documented. -- ssk.easyInputs.oneStick.create( group, { -- Parameters to oneStick builder: eventName = "myJoystickEvent", -- defaults to onJoystick -- Parameters to joystick builder: joyParams = { doNorm = true, -- Calculate normalized vectors and send in event -- This is expensive by default it is false } } ) -- 4. Now make an object to listen for joystick events and to do something -- when it gets them. local bob = display.newImageRect( group, "smiley.png", 48, 48 ) bob.x = centerX bob.y = centerY bob.mx = 0 bob.my = 0 bob.rate = 250 -- pixels-per-second bob.lastTime = system.getTimer() function bob.myJoystickEvent( self, event ) if( autoIgnore( "myJoystickEvent", self) ) then return end -- Table dumper from SSK (for debug) table.dump(event) self.mx = -event.nx self.my = -event.ny self.rotation = event.angle end; listen( "myJoystickEvent", bob ) -- Not a great way to move, but hey its a quick example... -- function bob.enterFrame( self ) if( autoIgnore( "enterFrame", self) ) then return end local curTime = system.getTimer() dt = self.lastTime - curTime self.lastTime = curTime self.x = self.x + self.mx \* self.rate \* dt/1000 self.y = self.y + self.my \* self.rate \* dt/1000 end; listen( "enterFrame", bob )