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

Show off your games, demos and other (playable) creations.
Post Reply
User avatar
darkmetalic
Prole
Posts: 17
Joined: Tue Feb 07, 2017 4:09 pm
Contact:

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

Post 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" >
]]
Attachments
toandroid.zip
Sample
(9.78 KiB) Downloaded 194 times
Last edited by darkmetalic on Wed Feb 15, 2017 8:35 pm, edited 2 times in total.
User avatar
Positive07
Party member
Posts: 1014
Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina

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

Post 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
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
User avatar
darkmetalic
Prole
Posts: 17
Joined: Tue Feb 07, 2017 4:09 pm
Contact:

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

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 167 guests