-1

Here is what I mean. On a small window:

On a small window

The spaceship aka the player's position is perfect, near the bottom. But if I go fullscreen:

in fullscreen

the position of the player is in the middle. How would I make it so it's always near the bottom? How would this work with other screen sizes?

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
fnTASY
  • 1
  • 1
  • Also if this isn't the right place to ask this question, i'm sorry, I'm confused – fnTASY Aug 25 '16 at 21:03
  • What code are you currently using to set the player's position? – chris Aug 25 '16 at 21:04
  • 1
    @chris Well idk if I'm explaining correctly but here is the code, it's a tutorial as I am new to love2. Github from tutorial: https://github.com/charles-l/gamedev_tutorial/blob/cd76f87db40fa3a802ccdf283c39745d1de1d19e/invaders.love/main.lua – fnTASY Aug 25 '16 at 21:06
  • 1
    Welcome to stackoverflow. Asking a clear question will make it easier to help you. please read this article to make sure that you get a good answer http://stackoverflow.com/help/how-to-ask – Ashkan S Aug 25 '16 at 21:29

2 Answers2

1

So, in your code, the player's y position is set to a fixed amount:

player.y = 550

This would be 550px from the top of the screen boundaries.

In the "fullscreen" screenshot, you simply have more pixels that you're working with. 550px is still the same amount relative to the top of the window, but now there's extra space below it.

If you're going to design your game to scale to different screen sizes, you need to decide how you want to handle the scale.

How would I make it so it's always near the bottom?

You can check the window height to fix the player to a certain number of pixels above the bottom of the screen, such as:

player.y = love.window.getHeight( ) - 100

https://love2d.org/wiki/love.window

How would this work with other screen sizes?

You're going to wind up with more or less space depending on the available number of pixels in your window. You have a number of options for asset placement and which one you choose is going to depend on your own desired outcome when the size of the window changes.

For example, you might want to allow the player to use their 3-monitor setup to view more of the game world. Or, you might want to keep all of your coordinates "fixed" and scale the graphics according to the window size.

chris
  • 2,893
  • 3
  • 20
  • 22
  • Thank you, I tried player.y = love.window.getHeight( ) - 100 but I get a error: Attempt to call field 'getHeight' – fnTASY Aug 25 '16 at 21:32
  • I would guess then that you are using love version 0.10.0+ ? There is a [patch note](https://love2d.org/wiki/0.10.0) saying this API was changed. Try using `love.graphics.getHeight()` (documented [here](https://love2d.org/wiki/love.graphics.getHeight)) instead of `love.window.getHeight()`. – chris Aug 25 '16 at 21:43
  • Thanks, I've tried that and it kinda works but on a smaller window size it just doesn't even show up? – fnTASY Aug 26 '16 at 00:01
1

Just like chris already said, depending on the size of the screen, the amount of pixels displayed vary. So use love.graphics.getHeight() to get the actual height of the screen in pixels.

Then you want to make sure, your object always stays at the same place, regardless of your screen size. You can achieve that if you subtract some pixels from the actual height of the screen (known from getHeight()). Something like this:

screenHeight = love.graphics.getHeight()
objectPositionY = screenHeight - 100
objectHeight = 10

But as you just mentioned in one of the comments above, on 'smaller' window sizes the object won't get displayed at all. That happens, if the screenHeight is smaller than the 100 pixels you subtract, in which case the object is displayed above/outside the visible screen, of course. But if you really want to create a game using such small windows, you can try something like this:

screenHeight = love.graphics.getHeight()
objectPositionY = screenHeight * 0.9
objectHeight = screenHeight * 0.05

This way the object always says on the exact same spot depending on the screenHeight, where 0 is the top and 1 is the bottom of the screen. Oh, and of course, you can do the same for the screenWidth as well.

But overall, you maybe should limit the minimum size to something useful.

And for the sake of completeness, if you want to create a game for multiple platforms (especially Android) using highDPI, you might want to consider love.window.getPixelScale as well!

nehegeb
  • 183
  • 8