Page 1 of 1

LOVE2D to Android - Landscape-Portrait or Horizontal-Vertical and all Touches

Posted: Wed Feb 15, 2017 8:04 pm
by darkmetalic
--Hello my friends, I will provide a simple and useful example to work with android system using LÖVE2D, I LOVE LÖVE and LÖVE LOVE ME LÖVE LOVE LOVE

Code: Select all

resize = {w=0,h=0}
screen = {w=0,h=0}
touch = {x=0,y=0}

function love.load()
smile = love.graphics.newImage("smile.png")	
end

function love.touchpressed( id, x, y, dx, dy, pressure )
touchpress=true
touchreleased=nil
end

function love.touchmoved( id, x, y, dx, dy, pressure )
touchmoved=true
touchreleased=nil
end

function love.touchreleased( id, x, y, dx, dy, pressure )
touchreleased=true	
touchmoved=nil
touchpress=nil
end

function love.draw()

screen.w, screen.h = love.graphics.getDimensions()

if screen.w > screen.h then
--landscape
resize.w, resize.h = screen.w/800 , screen.h/480
else
--portrait
resize.w, resize.h = screen.w/480 , screen.h/800
end

for i, id in ipairs(love.touch.getTouches()) do
touch.x, touch.y = love.touch.getPosition(id)
end

--in center and resized
love.graphics.draw(smile, (screen.w/2)-(smile:getWidth()/2), (screen.h/2)-(smile:getHeight()/2), 0 , resize.w, resize.h)

if touchmoved then
status="Moving"
elseif touchpress then
status="Pressing"
elseif touchreleased then
status="Released"
else
status="Sleeping"
end

love.graphics.print("Touch is "..status, 10, 10, 0, 3*resize.w, 3*resize.h)
end
--[[ conf.lua VERY IMPORTANT lines
t.identity = "data" --save dir in the internal storage
t.version = "0.10.1" -- if the builder...
t.accelerometerjoystick = false -- Enable the accelerometer on iOS and Android by exposing it as a Joystick (boolean)
t.externalstorage = true -- True to save files (and read from the save directory) in external storage on Android (boolean)

t.window.title = "Smile by Luiz Renato"
t.window.resizable = true -- Let the window be user-resizable (boolean)
t.window.minwidth = 480 --if vertical(portrait)
t.window.minheight = 480 --if horizontal(landscape)

AndroidManifest.xml VERY IMPORTANT line
android:screenOrientation="unspecified" >
]]

Re: LOVE2D to Android - Landscape-Portrait or Horizontal-Vertical and all Touches

Posted: Wed Feb 15, 2017 8:18 pm
by Positive07
Can you put in a code block?

[ code ] your code here [ / code ]

without the spaces it becomes

Code: Select all

your code here

Re: LOVE2D to Android - Landscape-Portrait or Horizontal-Vertical and all Touches

Posted: Wed Feb 15, 2017 8:32 pm
by darkmetalic
Positive07 wrote: Wed Feb 15, 2017 8:18 pm Can you put in a code block?

[ code ] your code here [ / code ]

without the spaces it becomes

Code: Select all

your code here
Yes