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

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

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

Post 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.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

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

Post by GijsB »

wait, where is the camera normally focused on?
User avatar
Rukiri
Citizen
Posts: 68
Joined: Mon Jun 27, 2011 5:52 am

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

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

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

Post by bartbes »

You can use math.min and math.max on the screen positions to enforce a minimum and maximum position.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

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

Post 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'
User avatar
lizard
Prole
Posts: 16
Joined: Wed Aug 04, 2010 6:38 pm
Location: Thailand

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

Post by lizard »

I use this modified code (from vrld-hump).
Attachments
camera.lua
modified vrld-hump camera with limits
(3.47 KiB) Downloaded 190 times
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests