Skip to content

Commit

Permalink
support touch mouse on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneSchwettmann committed Mar 18, 2017
1 parent d4a3045 commit 50ed112
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Draw.lua
Expand Up @@ -115,7 +115,7 @@ function drawTitleScreen()
love.graphics.setColor(255,255,255,255)
love.graphics.rectangle("fill", floor(centerX-200), floor(centerY-5-75+150), 400, 160 )
love.graphics.setColor(0,0,0,255)
love.graphics.printf("1 - Start 1 player game", 0, centerY-10-54+150,width,"center")
love.graphics.printf("1 or Click - Start 1 player game", 0, centerY-10-54+150,width,"center")
love.graphics.printf("2 - Start 2 player game", 0, centerY-10-27+150,width,"center")
love.graphics.printf("f - Toggle fullscreen", 0, centerY-10+150,width,"center")
love.graphics.printf("d - Toggle scaling (fullscreen only)", 0, centerY-10+27+150,width,"center")
Expand Down
30 changes: 26 additions & 4 deletions src/Input.lua
Expand Up @@ -2,9 +2,16 @@ function getInputPlayer(playerNumber)
local xInput,yInput=0,0
if playerNumber==1 then
local mouseX, mouseY = love.mouse.getPosition()
love.mouse.setPosition(centerX,centerY)
xInput=mouseScaleX*(mouseX-centerX)
yInput=mouseScaleY*(mouseY-centerY)
if touching then
xInput=mouseScaleX*(mouseX-mouseXOld)
yInput=mouseScaleY*(mouseY-mouseYOld)
mouseXOld=mouseX
mouseYOld=mouseY
else
love.mouse.setPosition(centerX,centerY)
xInput=mouseScaleX*(mouseX-centerX)
yInput=mouseScaleY*(mouseY-centerY)
end
elseif playerNumber==2 then
if love.keyboard.isDown("left") then
xInput = -500
Expand Down Expand Up @@ -91,10 +98,25 @@ function anyButtonPressed(joystick,numButtons)
return returnValue
end

function love.mousepressed(x, y, button)
function love.mousepressed(x, y, button, istouch)
if gameIsPaused==false and waitingForClick and button == 1 then
waitingForClick=false
end
if istouch then
touching = true
else
touching = false
end
if displayingTitleScreen then
if button == 1 then
numPlayers=1
startGame()
end
elseif gameLost then
if button == 1 then
titleScreen()
end
end
end

function love.keypressed(key, unicode)
Expand Down
6 changes: 5 additions & 1 deletion src/Load.lua
Expand Up @@ -12,7 +12,11 @@ function love.load()
height = 500
centerX = 400
centerY = 250


mouseXOld = centerX
mouseYOld = centerY
touching = false

desktopWidth=0 -- fullscreen size, will be populated later
desktopHeight=0 -- fullscreen size, will be populated later
fullscreenWidth=0
Expand Down

0 comments on commit 50ed112

Please sign in to comment.