I'm using the push library to adjust the screen size to the device screen and the suit library to create the text input element. I'm also using a font in assets/fonts/bit5x5.ttf
main.lua
Code: Select all
push = require 'vendor/push'
suit = require 'vendor/suit'
love.window.setMode(0, 0, {
fullscreen = true,
vsync = -1
})
WINDOW_WIDTH, WINDOW_HEIGHT = love.graphics.getDimensions()
VIRTUAL_WIDTH = 432
VIRTUAL_HEIGHT = 243
titleFont = love.graphics.newFont('assets/fonts/bit5x5.ttf', 32)
subtitleFont = love.graphics.newFont('assets/fonts/bit5x5.ttf', 16)
btnFont = love.graphics.newFont('assets/fonts/bit5x5.ttf', 8)
local input = {text = ""}
function love.load()
math.randomseed(os.time())
love.window.setTitle('Pong Rush')
love.graphics.setDefaultFilter('nearest', 'nearest')
push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
fullscreen = false,
resizable = false,
highdpi = true
})
end
function love.draw()
push:apply('start')
love.graphics.clear(40/255, 45/255, 52/255, 1)
love.graphics.setFont(titleFont)
love.graphics.printf('Pong Rush!', 0, 20, VIRTUAL_WIDTH, 'center')
love.graphics.setFont(subtitleFont)
love.graphics.printf('Multiplayer/Create', 0, 60, VIRTUAL_WIDTH, 'center')
suit.draw()
push:apply('end')
end
function love.update(dt)
local x, y = push:toGame(love.mouse.getPosition())
suit.updateMouse(x or 0, y or VIRTUAL_HEIGHT)
if input.text:len() > 25 then
input.text = string.sub(input.text, 1, 25);
end
love.graphics.setFont(btnFont)
suit.layout:reset(math.floor(VIRTUAL_WIDTH/2 - 100), math.floor(VIRTUAL_HEIGHT/2))
suit.layout:padding(10)
if suit.Input(input, suit.layout:row(200,20)).hit then
-- set the input box so the device will know where it is to not cover it with the soft keyboard
love.keyboard.setTextInput(true, math.floor(VIRTUAL_WIDTH/2 - 100), math.floor(VIRTUAL_HEIGHT/2), 200, 20)
end
end
function love.textedited(text, start, length)
-- for IME input
suit.textedited(text, start, length)
end
function love.textinput(t)
-- forward text input to SUIT
suit.textinput(t)
end
function love.keypressed(key)
-- forward keypresses to SUIT
suit.keypressed(key)
end
Code: Select all
function love.conf(t)
t.window.wdth = 1280
t.window.height = 720
t.modules.joystick = false
t.externalstorage = true
end
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<manifest package="org.love2d.android.executable"
android:installLocation="auto" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="23" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
<!-- OpenGL ES 2.0 -->
<uses-feature android:glEsVersion="0x00020000" />
<!-- Touchscreen support -->
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<!-- Game controller support -->
<uses-feature android:name="android.hardware.bluetooth" android:required="false" />
<uses-feature android:name="android.hardware.gamepad" android:required="false" />
<uses-feature android:name="android.hardware.usb.host" android:required="false" />
<!-- External mouse input events -->
<uses-feature android:name="android.hardware.type.pc" android:required="false" />
<application
android:allowBackup="true"
android:icon="@drawable/love"
android:label="Pong Rush"
android:usesCleartextTraffic="true"
android:hardwareAccelerated="true" >
<service android:name="org.love2d.android.DownloadService" />
<activity
android:name="org.love2d.android.GameActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden|navigation"
android:label="Pong Rush"
android:launchMode="singleTask"
android:screenOrientation="landscape"
android:resizeableActivity="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="tv.ouya.intent.category.GAME" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\\.love" />
<data android:host="*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="content" />
<data android:mimeType="application/x-love-game" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="content" />
<data android:mimeType="application/octet-stream" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/*" />
</intent-filter>
</activity>
<activity
android:name="org.love2d.android.DownloadActivity"
android:noHistory="true"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http"
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.love" />
<data android:scheme="https"
android:host="*"
android:mimeType="*/*"
android:pathPattern=".*\\.love" />
</intent-filter>
</activity>
</application>
</manifest>
With an outline rectangle to know that the position and size are correct adding a
Code: Select all
love.graphics.rectangle("line", math.floor(VIRTUAL_WIDTH/2 - 100), math.floor(VIRTUAL_HEIGHT/2), 200, 20)
And the final unwanted result (the soft keyboard covering the input when I select it to write):