I'm using Gamera to create a world space 2048x1536 in size ((1024x762)*2), and have a viewport/screen of the aforementioned 1024 resolution. I'm having a problem with the screen hitting the sides of the world before the mouse reaches the end of the world, which I know is in some way because there's 512 pixels on either side of the screen that aren't being taken into account.
I'm getting a percentage for my x and y by taking the mouse's position on the screen and dividing it by the width of the screen, which in turn gives me a decimal between 0 and 1 for it's location within the screen. I then take this percentage and multiply it by the size of the world, which returns the x position in the world space in relation to the mouse's position on the screen space. I then cam:setPosition(foundX, foundY), and it moves my camera around the world space based on the mouse's position.
however, as mentioned before, :setPosition is in relation to the center of the screen. in this specific case, I have 512 pixels to either side that will hit first, causing an unappealing stop when I get near an edge. my goal was to have it slowly head towards the edge, while just barely not usually reaching it (as in you're at 1% or 99% of the screen). the code I'm using here is below:
Code: Select all
menuWidth, menuHeight = love.graphics.getWidth(), love.graphics.getHeight()
mouseW, mouseH = love.mouse.getPosition()
menuLeft, menuTop, menuCamWidth, menuCamHeight = menuCam:getWorld()
screenLeft, screenTop, screenCamWidth, screenCamHeight = menuCam:getVisible()
screenRight, screenBottom = screenLeft + 1024, screenTop + 768
camXPercent, camYPercent = (mouseW/menuWidth), (mouseH/menuHeight)
modCamX, modCamY = (menuCamWidth * camXPercent), (menuCamHeight * camYPercent)
menuCam:setPosition(modCamX, modCamY)
if anybody has any ideas on what to try, I will gladly test them!