Any Tutorials On Quadrant Based Controls?

Hello, 

My goal is to create a game where there are no on screen controls - just sections of the screen that does something

for example: 

onQ3Touch move left

on Q4Touch move right

on Q1Q2Touch jump 

Q1-4 being quadrants. 

if anyone can point me to the right place I greatly appreciate it. 

I already have an idea of how it is supposed to be done - I’m guessing transparent rectangles - but I’m not 100% sure how. 

Thanks,

Marc 

Just add a Runtime touch listener like this:

[lua]Runtime:addEventListener(“touch”, yourListener)[/lua]

Then within your function listener check the event.x and event.y fields to determine which quadrant you are in and then call functions that are for each quadrant.

[lua]local function yourListener(event) – make sure you have event as a parameter

    if event.x < display.contentWidth/2 then
         if event.y < display.contentHeight/2 then
             – top left quadrant function
        else
            – bottom left quadrant function
        end
    else
        if event.y < display.contentHeight/2 then
            – top right quadrant function
        else
            – bottom right quadrant function

        end
    end
end[/lua]

Note that you need to declare your function BEFORE you add the Runtime listener.

Just remember - if you don’t mind me interjecting here - if you want to save CPU cycles in your game (every little bit counts, especially if you’re doing a lot of things like this), avoid dividing by 2 when you can multiply by 0.5.  Division is a more taxing instruction than multiplication.

Also, you can use display.contentCenterX and display.contentCenterY , which is identical to display.contentWidth * 0.5 and display.contentHeight * 0.5 , respectively.

Good point BeyondtheTech. I always forget that division takes longer. Do you know how bad it really is?

Probably negligible if it’s just done every once in a while, but in my game where I’m running tons of calculations in the enterFrame event listener, I need to make sure it’s in and out at lightning speed, or frames could start skipping.  I’m not taking ANY chances!

Just add a Runtime touch listener like this:

[lua]Runtime:addEventListener(“touch”, yourListener)[/lua]

Then within your function listener check the event.x and event.y fields to determine which quadrant you are in and then call functions that are for each quadrant.

[lua]local function yourListener(event) – make sure you have event as a parameter

    if event.x < display.contentWidth/2 then
         if event.y < display.contentHeight/2 then
             – top left quadrant function
        else
            – bottom left quadrant function
        end
    else
        if event.y < display.contentHeight/2 then
            – top right quadrant function
        else
            – bottom right quadrant function

        end
    end
end[/lua]

Note that you need to declare your function BEFORE you add the Runtime listener.

Just remember - if you don’t mind me interjecting here - if you want to save CPU cycles in your game (every little bit counts, especially if you’re doing a lot of things like this), avoid dividing by 2 when you can multiply by 0.5.  Division is a more taxing instruction than multiplication.

Also, you can use display.contentCenterX and display.contentCenterY , which is identical to display.contentWidth * 0.5 and display.contentHeight * 0.5 , respectively.

Good point BeyondtheTech. I always forget that division takes longer. Do you know how bad it really is?

Probably negligible if it’s just done every once in a while, but in my game where I’m running tons of calculations in the enterFrame event listener, I need to make sure it’s in and out at lightning speed, or frames could start skipping.  I’m not taking ANY chances!