Page 2 of 2
Re: Only showing 64X63 of my map
Posted: Thu Jul 28, 2011 3:03 pm
by tentus
Kadoba wrote:You mean have the view stay within the boundary of the map? You'll just have to limit the view yourself.
You should be able to do it with something similar to this:
Code: Select all
local mapWidthLimit = map.width * map.tilewidth - love.graphics.getWidth()
local mapHeightLimit = map.height * map.tileheight - love.graphics.getHeight()
if x > mapWidthLimit then x = mapWidthLimit end
if y > mapHeightLimit then y = mapHeightLimit end
if x < 0 then x = 0 end
if y < 0 then y = 0 end
Wouldn't this be marginally more efficient?
Code: Select all
local mapWidthLimit = (map.width * map.tilewidth) - love.graphics.getWidth()
local mapHeightLimit = (map.height * map.tileheight) - love.graphics.getHeight()
if x < 0 then
x = 0
elseif x > mapWidthLimit then
x = mapWidthLimit
end
if y < 0 then
y = 0
elseif y > mapHeightLimit then
y = mapHeightLimit
end
Re: Only showing 64X63 of my map
Posted: Thu Jul 28, 2011 3:23 pm
by Kadoba
Yes but I was mostly writing it for clarity.
This is even more efficient:
Code: Select all
local mapWidthLimit = map.width * map.tilewidth - love.graphics.getWidth()
local mapHeightLimit = map.height * map.tileheight - love.graphics.getHeight()
x = x < 0 and 0 or x > mapWidthLimit and mapWidthLimit or x
y = y < 0 and 0 or y > mapHeightLimit and mapHeightLimit or y
Re: Only showing 64X63 of my map
Posted: Thu Jul 28, 2011 5:25 pm
by Rukiri
Error.
Attempt to compare nil with number.
I've coded something similar but it had no effect.
Re: Only showing 64X63 of my map
Posted: Thu Jul 28, 2011 7:39 pm
by Kadoba
I can't help you unless I see the code you used.
Re: Only showing 64X63 of my map
Posted: Sat Jul 30, 2011 7:02 am
by Rukiri
Code: Select all
local mw = map.width - love.graphics.getWidth()
local mh = map.height - love.graphics.getHeight()
if x >= mw then x = mw end
if y >= mh then y = mh end
if x <= 0 then x == 0 end
if y <= 0 then y == 0 end
The code itself isn't much different to what you posted.
I had this placed in the desert examples update function.
Re: Only showing 64X63 of my map
Posted: Sun Jul 31, 2011 6:42 pm
by tentus
Rukiri wrote:Code: Select all
if x >= mw then x = mw end
if y >= mh then y = mh end
if x <= 0 then x == 0 end
if y <= 0 then y == 0 end
The last two lines are wrong. Should be:
Code: Select all
if x > mw then x = mw end
if y > mh then y = mh end
if x < 0 then x = 0 end
if y < 0 then y = 0 end
Also you should just use < and > rather than <= and >=, the = is redundant.
Re: Only showing 64X63 of my map
Posted: Mon Aug 01, 2011 5:24 am
by Kadoba
You also probably didn't define x and y, which is why it's giving you a nil compare error. I meant for that to be the translation/view coordinators.
Re: Only showing 64X63 of my map
Posted: Sun Aug 07, 2011 4:20 am
by Rukiri
I did go and define X, Y but didn't really change anything.
Re: Only showing 64X63 of my map
Posted: Sun Aug 07, 2011 9:45 am
by Kadoba
Ok. Let's try this again. What is the code that you are using and the exact line and error that it gives you?