SSK2: Fixed joysticks and 8 directional sticks?

I noticed that in some mobile games such as Soul Knight, there are options to change joysticks to be fixed, or 8 directional.

How could I go about replicating that with SSK2 joysticks?

Some tips would be nice as the joystick:touch function looks a bit tricky, maybe a heads-up on what parts of the code to focus on…

What it sounds like you’re asking for is to “interpret the output from the SSK2 joystick as Cardinal+”.

I define Cardinal as:

  • N - 0-degrees
  • W - 90-degrees
  • S - 180-degrees
  • E - 270-degrees

Cardinal + simply adds four additional directions NW, SW, SE, NE to this.
 
So, how would I go about implementing this system using SSK2’s joystick?  Like this…

local player = ... code to make player object. function player.doNorth( self ) -- Code to handle moving north or whatever .... end function player.doNorthWest( self ) -- Code to handle moving north-west or whatever .... end ... etc.

Now create a custom joystick listener on the player object:

function player.onJoystick( self, event ) local angle = event.angle local offset = 22.5 if( angle \<= offset ) then self:doNorth() elseif( angle \> offset and angle \<= 45 + offset ) then self:doNorthWest() elseif( angle \> 45 + offset and angle \<= 90 + offset ) then self:doWest() elseif( angle \> 90 + offset and angle \<= 135 + offset ) then self:doSouthEast() elseif( angle \> 135 + offset and angle \<= 180 + offset ) then self:doSouth() elseif( angle \> 180 + offset and angle \<= 225 + offset ) then self:doSouthWest() elseif( angle \> 225 + offset and angle \<= 270 + offset ) then self:doWest() elseif( angle \> 270 + offset and angle \<= 315 + offset ) then self:doNorthEast() elseif( angle \> 315 + offset ) then self:doNorth() end end; listen( "onJoystick", player )

Note 1: You do not need the doNorth(), noEast(), etc. functions.  I just presented it this way because that is a cleaner way to code and demo it.  

 
Note 2: To any readers who don’t agree with the angles, this is based on how SSK2’s angles work, not the traditional Cartesian values you were taught in school.

Offset

Before you ask, that ‘offset’ bit it to allow the regions around the cardinal+ direction to represent that direction.

For example, any angle between 337.5 and 0 is North.  As well, 0 … 22.5 is also North.

Similarly, the angles between  22.5 and 67.5 is North West.

Visuals

I did not address visual feedback for the joystick control and I won’t unless you want to pay for a hit.  That is just too much work for a quicky free answer.  :)  Sorry.

Fixed Joystick

I almost missed this.  I think you were also asking how to force the SSK2 joystick to stay in one place .

I don’t usually do this, but IIRC the library should support it like this:

ssk.easyInputs.joystick.create( group, x, y, { inputObj = nil } )

Hi roaminggamer,

You can write it simpler because inputObj parameter defaults to nil if not provided :

ssk.easyInputs.joystick.create( group, x, y )

Have a nice day:)

ldurniat

Thanks, I’m aware of this, but I wanted to point out the important field.  i.e. I want to be sure he doesn’t assign a value to it. :slight_smile:

Thank you for all the tips, this is for a later stage in the game, so I am not too worried about it now. I just wanted to have a general idea of how to do some of it. 

What it sounds like you’re asking for is to “interpret the output from the SSK2 joystick as Cardinal+”.

I define Cardinal as:

  • N - 0-degrees
  • W - 90-degrees
  • S - 180-degrees
  • E - 270-degrees

Cardinal + simply adds four additional directions NW, SW, SE, NE to this.
 
So, how would I go about implementing this system using SSK2’s joystick?  Like this…

local player = ... code to make player object. function player.doNorth( self ) -- Code to handle moving north or whatever .... end function player.doNorthWest( self ) -- Code to handle moving north-west or whatever .... end ... etc.

Now create a custom joystick listener on the player object:

function player.onJoystick( self, event ) local angle = event.angle local offset = 22.5 if( angle \<= offset ) then self:doNorth() elseif( angle \> offset and angle \<= 45 + offset ) then self:doNorthWest() elseif( angle \> 45 + offset and angle \<= 90 + offset ) then self:doWest() elseif( angle \> 90 + offset and angle \<= 135 + offset ) then self:doSouthEast() elseif( angle \> 135 + offset and angle \<= 180 + offset ) then self:doSouth() elseif( angle \> 180 + offset and angle \<= 225 + offset ) then self:doSouthWest() elseif( angle \> 225 + offset and angle \<= 270 + offset ) then self:doWest() elseif( angle \> 270 + offset and angle \<= 315 + offset ) then self:doNorthEast() elseif( angle \> 315 + offset ) then self:doNorth() end end; listen( "onJoystick", player )

Note 1: You do not need the doNorth(), noEast(), etc. functions.  I just presented it this way because that is a cleaner way to code and demo it.  

 
Note 2: To any readers who don’t agree with the angles, this is based on how SSK2’s angles work, not the traditional Cartesian values you were taught in school.

Offset

Before you ask, that ‘offset’ bit it to allow the regions around the cardinal+ direction to represent that direction.

For example, any angle between 337.5 and 0 is North.  As well, 0 … 22.5 is also North.

Similarly, the angles between  22.5 and 67.5 is North West.

Visuals

I did not address visual feedback for the joystick control and I won’t unless you want to pay for a hit.  That is just too much work for a quicky free answer.  :)  Sorry.

Fixed Joystick

I almost missed this.  I think you were also asking how to force the SSK2 joystick to stay in one place .

I don’t usually do this, but IIRC the library should support it like this:

ssk.easyInputs.joystick.create( group, x, y, { inputObj = nil } )

Hi roaminggamer,

You can write it simpler because inputObj parameter defaults to nil if not provided :

ssk.easyInputs.joystick.create( group, x, y )

Have a nice day:)

ldurniat

Thanks, I’m aware of this, but I wanted to point out the important field.  i.e. I want to be sure he doesn’t assign a value to it. :slight_smile:

Thank you for all the tips, this is for a later stage in the game, so I am not too worried about it now. I just wanted to have a general idea of how to do some of it.