Discord
Login
Community
DARK THEME

Mobile game dev

I haven't found such info on the documentation, so I'm posting a question here:

  1. How can I detect an Android OS back button press, so I can pause my game? In general, is there a way to check if the user has moved the app in the background, so we can pause it?

  2. Regarding screen size, I have set my game aspect ratio to 16:9 or above and I'm curious about the "above" part. Doing a screen.fillRect(0,0,screen.width,screen.height,"#111") in the draw function, I see that in phones with aspect rations longer than 16:9 (for example 18:9 or 21:9), the filled area leaves two large empty bands above and below the actual play area. Is there a way to force the game to run full screen and have then screen.width and screen.height parameters point to the correct values?

Regards, Spyros

Just to add some more info, regarding how the game looks on a phone, I'm talking about just pointing the browser to the game URL, using the QR code; I haven't tested yet how the exported APK works.

  1. Use the "Any" aspect ratio. When the size of the window in which the game is placed changes, the values of the screen.width parameter will change.
init = function()
end

update = function()
end

draw = function()
  screen.clear()
  screen.setColor("#FFF")
  screen.drawRect( 0, 0, screen.width, screen.height )
  screen.drawRect( 0, 0, screen.width-8, screen.height-8 )  
  screen.drawText( "screen.width = "+screen.width ,0,0,20)
  screen.drawText( "screen.height = "+screen.height,0,-20,20)              
end

On my old phone (android 6) the apk doesn't work. And they are suspiciously small.

Thanks, that did the trick.

Here is the final result, for anyone interested:

https://microstudio.io/spyros1973/codebreaker/

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community