Page 1 of 1

stopping camera at the edge of a tile map (black_background)

Posted: Wed Jul 27, 2011 10:13 pm
by Rukiri
Right now the only problem I'm having is stopping the camera at the edge of a tile-map, again I'm using the advanced tile loader to load my maps.

Before I do anything serious I want to be able to load and move a sprite and map accordingly which I've learned with game maker over the years and learning true tile-based stuff with love.

The image below shows the issue, it's not an issue but the camera should not show it in an actual game.
Image

I'm basically just using the default camera movement that was with the a.t.l., while it's nice it should not go outside the map it loads and shows the black background which annoys me as not every map is going to cover an area with trees to block the player from moving the camera which eventually would show the black background.

so I'm wondering if anyone has an idea of stopping the camera movement if the edge/end of the map was reached depending on which direction the character was moving in, doesn't matter if it's up,down,left,right or diagonal panning it should stop at the edge.

Just for reference this is the code from the demo.

Code: Select all

if love.keyboard.isDown("up") then ty = ty + 250*dt end
	if love.keyboard.isDown("down") then ty = ty - 250*dt end
	if love.keyboard.isDown("left") then tx = tx + 250*dt end
	if love.keyboard.isDown("right") then tx = tx - 250*dt end
so like for example.
if map_edge_reached_x then stop_camera = true end
if map_edge_reached_y then stop_camera = true end

yea bad example but would be something similar that would be used so the camera can't pan outside the map you load.

Getting maps to work is really my only issue with Love I've been able to do at least what I've tested that I could with Game Maker so far and that makes me happy.

Re: stopping camera at the edge of a tile map (black_backgro

Posted: Wed Jul 27, 2011 10:16 pm
by GijsB
wait, where is the camera normally focused on?

Re: stopping camera at the edge of a tile map (black_backgro

Posted: Wed Jul 27, 2011 10:20 pm
by Rukiri
tx and ty if I'm reading the code right.

But if it were focusing on tx,ty it wouldn't stop the camera just because it's not on a map anymore.

I'd love to release my zelda example but can't because of this issue, I have most of link's sword functions done but don't want to focus too much on movement until the camera problem is fixed.

Re: stopping camera at the edge of a tile map (black_backgro

Posted: Wed Jul 27, 2011 10:27 pm
by bartbes
You can use math.min and math.max on the screen positions to enforce a minimum and maximum position.

Re: stopping camera at the edge of a tile map (black_backgro

Posted: Wed Jul 27, 2011 10:39 pm
by GijsB
oke, how wide is your view?

because then we just half your view, minus that on the wide of the map, and there you have your 'border'

Re: stopping camera at the edge of a tile map (black_backgro

Posted: Sun Jul 31, 2011 8:54 am
by lizard
I use this modified code (from vrld-hump).