Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code snippets for the Corona SDK Tutorial: Game controllers and axes (https://coronalabs.com/blog/2013/09/24/tutorial-controllers-and-axis)
local redPlayer = display.newRect( display.contentCenterX-15, display.contentCenterY-15, 30, 30 )
redPlayer:setFillColor( 1, 0, 0 )
redPlayer.x = display.contentCenterX
redPlayer.y = display.contentCenterY
redPlayer.isMovingX = 0
redPlayer.isMovingY = 0
redPlayer.isRotatingX = 0
redPlayer.isRotatingY = 0
redPlayer.thisAngle = 0
redPlayer.lastAngle = 0
redPlayer.rotationDistance = 0
redPlayer.isGrowing = 0
redPlayer.color = "red"
local greenPlayer = display.newRect( display.contentCenterX-15, display.contentCenterY-15, 30, 30 )
greenPlayer:setFillColor( 0, 1, 0 )
greenPlayer.isMovingX = 0
greenPlayer.isMovingY = 0
greenPlayer.isRotatingX = 0
greenPlayer.isRotatingY = 0
greenPlayer.thisAngle = 0
greenPlayer.lastAngle = 0
greenPlayer.rotationDistance = 0
greenPlayer.isGrowing = 0
greenPlayer.color = "green"
-- "blueDot" isn't a player, just a visual to show the physical stick movement
local blueDot = display.newCircle( display.contentCenterX, display.contentCenterY, 7 )
blueDot:setFillColor( 0, 0, 1 )
-- "whiteDot" is a visual representation to demonstrate how well the stick
-- settles back to center; ideally, the blue circle should center back with
-- white dot, but if it doesn't, this exhibits the stick "slop" factor that
-- you should compensate for
local whiteDot = display.newCircle( display.contentCenterX, display.contentCenterY, 2 )
whiteDot:setFillColor( 1 )
-- These UI elements show the current keypress and axis information
local myKeyDisplayText = display.newText( "", 0, 0, 300, 0, native.systemFontBold, 10 )
myKeyDisplayText.x = display.contentWidth / 2
myKeyDisplayText.y = 50
local myAxisDisplayText = display.newText( "", 0, 0, native.systemFontBold, 20 )
myAxisDisplayText.x = display.contentWidth / 2
myAxisDisplayText.y = display.contentHeight - 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.