Tile based scrolling

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
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Tile based scrolling

Post by Robin »

Ryne wrote:Yea that distance code makes more sense now, Though I still don't understand what you mean about changing the player position. If I change the player position (meaning affect his x/y) then wouldn't that mess with the scrolling then?
Why? It would still have the same effect, as long as you make the "camera" depend on the player position.
Help us help you: attach a .love.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Tile based scrolling

Post by Ryne »

Robin wrote: Why? It would still have the same effect, as long as you make the "camera" depend on the player position.
Thank's again for the reply, though I'm still lost. I guess I don't understand the code enough to work with it. I don't know how to do any of the things you suggested. I didn't know there was any camera in place, nor do I know how to force it to player position.. I appreciate the help though I think I'm sort of a lost cause on this one.
@rynesaur
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Tile based scrolling

Post by Robin »

Ryne wrote:I didn't know there was any camera in place,
The "camera" is just the offset at which you draw things. (Would you share a .love so we can help you a bit better?)
I believe the variables were called map_x and map_y.
Ryne wrote:nor do I know how to force it to player position..

Code: Select all

-- this in love.update, after the player position is changed:
map_x = player.x
map_y = player.y
A better solution would be to use the player x/y for the offset.
Ryne wrote:I appreciate the help though I think I'm sort of a lost cause on this one.
I don't think so. :P
Help us help you: attach a .love.
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Tile based scrolling

Post by Ryne »

Robin wrote:
Ryne wrote:I didn't know there was any camera in place,
The "camera" is just the offset at which you draw things. (Would you share a .love so we can help you a bit better?)
I believe the variables were called map_x and map_y.
Ryne wrote:nor do I know how to force it to player position..

Code: Select all

-- this in love.update, after the player position is changed:
map_x = player.x
map_y = player.y
A better solution would be to use the player x/y for the offset.
Ryne wrote:I appreciate the help though I think I'm sort of a lost cause on this one.
I don't think so. :P
I'm a little secretive of my game so far, luckily I have been working on vastly different graphics the last few days. I also haven't had a chance to fix my code, with the thing's you guys have posted so far (like the enemies updating). Anyway, here it is, ugly as ever.

http://dl.dropbox.com/u/7905642/Simon%2 ... simon.love

I also added "+ 16" to "offset_x" so that it would stop clipping the map on the left side of the screen. In case that causes issues with anything.
@rynesaur
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Tile based scrolling

Post by Robin »

So… it works?
Help us help you: attach a .love.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Tile based scrolling

Post by tentus »

You have some power of 2 problems. An easy fix is to require this code:

Code: Select all

do
	local newimage = love.graphics.newImage
	function love.graphics.newImage(source)
		if type(source) == "string" then
			source = love.image.newImageData(source)
		end
		local width = source:getWidth()
		local height = source:getHeight()
		local powerwidth = math.pow(2, math.ceil(math.log(width)/math.log(2)))
		local powerheight = math.pow(2, math.ceil(math.log(height)/math.log(2)))
		if powerwidth ~= width or powerheight ~= height then
			local padded = love.image.newImageData(powerwidth, powerheight)
			padded:paste(source, 0, 0)
			return newimage(padded)
		end
		return newimage(source)
	end
end
Kurosuke needs beta testers
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Tile based scrolling

Post by Ryne »

Robin wrote:So… it works?
No, this is what I was talking about. The player and the enemies seem to be placed fine / all of the tile based stuff seems for work. Though now my "follow the player" code is broken.

This:

Code: Select all

for i=1, #enemies do
		if not CheckCollision(player, enemies[i]) and Distance(player, enemies[i]) then
			-- the vector from enemy to the player
			local vx = player.x - enemies[i].x
			local vy = player.y - enemies[i].y

			-- normalize it, i.e. divide it by it's length
			local length = math.sqrt(vx * vx + vy * vy)
			vx = vx / length
			vy = vy / length

			-- move the zombie towards the player
			enemies[i].x = enemies[i].x + vx * enemies[i].speed * dt
			-- enemies[i].y = enemies[i].y + vy * enemies[i].speed * dt
		end
		
		if CheckCollision(player, enemies[i]) and enemies[i].dir == "left" then
		enemies[i].anim = eanim.idleleft
		
		elseif CheckCollision(player, enemies[i]) and enemies[i].dir == "right" then
		enemies[i].anim = eanim.idleright
		end
	end	
tentus wrote:You have some power of 2 problems. An easy fix is to require this code:
What exact problem does that fix? Just so I know.
@rynesaur
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Tile based scrolling

Post by Ryne »

Robin wrote:So… it works?
No, this is what I was talking about. The player and the enemies seem to be placed fine / all of the tile based stuff seems for work. Though now my "follow the player" code is broken.

This:

Code: Select all

for i=1, #enemies do
		if not CheckCollision(player, enemies[i]) and Distance(player, enemies[i]) then
			-- the vector from enemy to the player
			local vx = player.x - enemies[i].x
			local vy = player.y - enemies[i].y

			-- normalize it, i.e. divide it by it's length
			local length = math.sqrt(vx * vx + vy * vy)
			vx = vx / length
			vy = vy / length

			-- move the zombie towards the player
			enemies[i].x = enemies[i].x + vx * enemies[i].speed * dt
			-- enemies[i].y = enemies[i].y + vy * enemies[i].speed * dt
		end
		
		if CheckCollision(player, enemies[i]) and enemies[i].dir == "left" then
		enemies[i].anim = eanim.idleleft
		
		elseif CheckCollision(player, enemies[i]) and enemies[i].dir == "right" then
		enemies[i].anim = eanim.idleright
		end
	end	
tentus wrote:You have some power of 2 problems. An easy fix is to require this code:
What exact problem does that fix, and what do you mean by "power of 2 problems"? Just so I know.
@rynesaur
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Tile based scrolling

Post by TechnoCat »

Ryne wrote:
tentus wrote:You have some power of 2 problems. An easy fix is to require this code:
What exact problem does that fix, and what do you mean by "power of 2 problems"? Just so I know.
http://love2d.org/wiki/PO2_Syndrome
User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Tile based scrolling

Post by Ryne »

TechnoCat wrote:
Ryne wrote:
tentus wrote:You have some power of 2 problems. An easy fix is to require this code:
What exact problem does that fix, and what do you mean by "power of 2 problems"? Just so I know.
http://love2d.org/wiki/PO2_Syndrome
Oh right, I misunderstood "divisible by 2" for "power of 2". My mistake. Though that code make my player/enemy images blink on and off?
@rynesaur
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 217 guests