Cameras in Love2D (Tutorials)

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
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Cameras in Love2D (Tutorials)

Post by BlackBulletIV »

Thanks for your feedback. Yes it is top left. I agree that would be a good thing, but I can't be bothered changing the tutorial now; I'll leave that up to the user.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Cameras in Love2D (Tutorials)

Post by molul »

Hi BlackBulletIV. I'm having a hard time trying to mix part 2 and 3 of your tutorial. I'm trying to have a sprite (the player), the ground it walks on, and then 5 scroll planes behind.

When I create each layer, the sprite's layer has to get a scale = 0, so it's not moved by the camera, but only by the player's input. Now, no matter what value I set the other layer's scales, if they're not != 0 they will move along with the player, but if I set them to anything != 0, they'll move faster than the player.

I'm trying to figure out a way to make "1" the scale value for layers that shouldn't be moved, but I can't figure out a way. If someone has stepped onto this problem before, I'd appreciate their advice a lot.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

Re: Cameras in Love2D (Tutorials)

Post by molul »

False alarm, I managed to get it working. The trick was to forget all the layers thing. So in the love.load function you should call to this function:

Code: Select all

function createScrollPlanes()
	scrollPlanes = {}
	for i = 1, 5 do
		local sp = {
			x = 0,
			y = 0,
			repeatX = true,
			repeatY = false,
			img = love.graphics.newImage(gImagesPath.."stages/mountain/s".. i ..".png"),
			q = love.graphics.newQuad(0, 0, 2560, 720, 2560, 720),
		}
		table.insert(scrollPlanes, sp)
	end
end

And then in love.draw:

Code: Select all

function love.draw()
	drawBackground()
	camera:set()
		drawGround() --can be a tiled map
		drawPlayer() 
		drawForeground() --in case you want a scroll layer in front of the player
	camera:unset()
end	
It's funny how I usually find the answer to something right after I ask for help... Sorry for the inconveniences.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Roland Chastain and 81 guests