Only showing 64X63 of my map

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Only showing 64X63 of my map

Post 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
Kurosuke needs beta testers
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Only showing 64X63 of my map

Post 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
User avatar
Rukiri
Citizen
Posts: 68
Joined: Mon Jun 27, 2011 5:52 am

Re: Only showing 64X63 of my map

Post by Rukiri »

Error.
Attempt to compare nil with number.

I've coded something similar but it had no effect.
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Only showing 64X63 of my map

Post by Kadoba »

I can't help you unless I see the code you used.
User avatar
Rukiri
Citizen
Posts: 68
Joined: Mon Jun 27, 2011 5:52 am

Re: Only showing 64X63 of my map

Post 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.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Only showing 64X63 of my map

Post 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.
Kurosuke needs beta testers
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Only showing 64X63 of my map

Post 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.
User avatar
Rukiri
Citizen
Posts: 68
Joined: Mon Jun 27, 2011 5:52 am

Re: Only showing 64X63 of my map

Post by Rukiri »

I did go and define X, Y but didn't really change anything.
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Only showing 64X63 of my map

Post 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?
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 204 guests