Foreground/Background Scrolling Implementation

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
The Burrito
Party member
Posts: 153
Joined: Mon Sep 21, 2009 12:14 am
Contact:

Re: Foreground/Background Scrolling Implementation

Post by The Burrito »

I use the full physics engine or AABB collision for most of my tests / demos, but you probably want something in between. Take a look at Hardon Collider if you haven't already, it's pretty good.

If you aren't planning on having much else you could write some kind of simple slope handler thing that prevents the player from ever being below the slope, but that will be kind of a waste if you're going to eventually include platforms or something and have to do collision checks for those too.
User avatar
verilog
Citizen
Posts: 97
Joined: Thu Nov 03, 2011 3:15 am
Contact:

Re: Foreground/Background Scrolling Implementation

Post by verilog »

I see, let me expand on my "slope-collision" idea a bit to see if the results are good enough. I'll make sure to check out Hardon Collider, though, thanks for the heads up! :awesome:
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: Foreground/Background Scrolling Implementation

Post by MarekkPie »

I don't know what your theory is, but most of the time for non-AABB collisions people use the separating axis theorem. Here is a VERY detailed explanation of it, though there is no code to see what is going on.

That said, both Box2D (and it looks like HardonCollider as well) use SAT if you don't want to melt your brain.
User avatar
AntonioModer
Party member
Posts: 202
Joined: Fri Jun 15, 2012 5:31 pm
Location: Belarus
Contact:

Re: Foreground/Background Scrolling Implementation

Post by AntonioModer »

LOVE 0.8.0 background scrolling

Code: Select all

camera = {}
camera.x = 0;
camera.y = 0;
--== BACKGROUND ==--
-- Setup --
backgr = {};
backgr.image = love.graphics.newImage("image.png");
backgr.imageSize = backgr.image:getWidth();
backgr.spriteBatch = love.graphics.newSpriteBatch(backgr.image, 9);	-- =9 if screen=640x480, backgr.imageSize=512 !!!

function drawBackground()
	love.graphics.setColor(255,255,255,255)
	local floor, backgr, camera = math.floor, backgr, camera;
	backgr.spriteBatch:clear()
	backgr.spriteBatch:bind()	
	for x = floor((camera.x-(love.graphics.getWidth()/2)+0)/backgr.imageSize), 
                         floor((camera.x+(love.graphics.getWidth()/2)-0)/backgr.imageSize) do
		for y = floor((camera.y-(love.graphics.getHeight()/2)+0)/backgr.imageSize), 
                                       floor((camera.y+(love.graphics.getHeight()/2)-0)/backgr.imageSize) do
			backgr.spriteBatch:add(x*backgr.imageSize, y*backgr.imageSize)
		end
	end
	backgr.spriteBatch:unbind()
	love.graphics.draw(backgr.spriteBatch,0,0);
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests