Why? It would still have the same effect, as long as you make the "camera" depend on the player position.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?
Tile based scrolling
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Tile based scrolling
Help us help you: attach a .love.
Re: Tile based scrolling
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.Robin wrote: Why? It would still have the same effect, as long as you make the "camera" depend on the player position.
@rynesaur
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Tile based scrolling
The "camera" is just the offset at which you draw things. (Would you share a .love so we can help you a bit better?)Ryne wrote:I didn't know there was any camera in place,
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
I don't think so.Ryne wrote:I appreciate the help though I think I'm sort of a lost cause on this one.
Help us help you: attach a .love.
Re: Tile based scrolling
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.Robin wrote:The "camera" is just the offset at which you draw things. (Would you share a .love so we can help you a bit better?)Ryne wrote:I didn't know there was any camera in place,
I believe the variables were called map_x and map_y.
Ryne wrote:nor do I know how to force it to player position..A better solution would be to use the player x/y for the offset.Code: Select all
-- this in love.update, after the player position is changed: map_x = player.x map_y = player.y
I don't think so.Ryne wrote:I appreciate the help though I think I'm sort of a lost cause on this one.
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
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Tile based scrolling
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
Re: Tile based scrolling
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.Robin wrote:So… it works?
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
What exact problem does that fix? Just so I know.tentus wrote:You have some power of 2 problems. An easy fix is to require this code:
@rynesaur
Re: Tile based scrolling
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.Robin wrote:So… it works?
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
What exact problem does that fix, and what do you mean by "power of 2 problems"? Just so I know.tentus wrote:You have some power of 2 problems. An easy fix is to require this code:
@rynesaur
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: Tile based scrolling
http://love2d.org/wiki/PO2_SyndromeRyne wrote:What exact problem does that fix, and what do you mean by "power of 2 problems"? Just so I know.tentus wrote:You have some power of 2 problems. An easy fix is to require this code:
Re: Tile based scrolling
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?TechnoCat wrote:http://love2d.org/wiki/PO2_SyndromeRyne wrote:What exact problem does that fix, and what do you mean by "power of 2 problems"? Just so I know.tentus wrote:You have some power of 2 problems. An easy fix is to require this code:
@rynesaur
Who is online
Users browsing this forum: Bing [Bot] and 217 guests