Change the size of your animation cells I would guess.Ryne wrote: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?
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.
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: Tile based scrolling
Re: Tile based scrolling
My player/enemy animations are all 32x32 images. It won't matter anyway. Once I get my code all settled I'm going to start from scratch and clean up a lot of the code as well as start with a new set of images.TechnoCat wrote:Change the size of your animation cells I would guess.Ryne wrote: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?
Actually, this may be a stupid question, but to be "po2 safe" does it HAVE to be a power of 2(meaning 8x8, 9x9, 10x10) or just divisible by 2? Is the resolution I'm using for my game 320x180 po2 safe, or should it be 324 x 196?
Anyway, I don't want to get my thread sidetracked so in case Robin comes back please check the previous page for the reply to your question
@rynesaur
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Tile based scrolling
Power of two means that it can only be either 2, or the previous number multiplied by two. In other words, it's made only by multiplying 2s.Ryne wrote: Actually, this may be a stupid question, but to be "po2 safe" does it HAVE to be a power of 2(meaning 8x8, 9x9, 10x10) or just divisible by 2? Is the resolution I'm using for my game 320x180 po2 safe, or should it be 324 x 196?
- 2
- 2*2 = 4
- 2*2*2 = 8
- 2*2*2*2 = 16
- 2*2*2*2*2 = 32
- 64,128,256,512,1024,2048, etc
Both dimensions have to be po2, but they don't have to be the same. For example, a 32x64 image is po2-safe.
This applies to images and quads, but I don't think it applies to screen resolutions; those can be more or less arbitrary AFAIK.
When I write def I mean function.
Re: Tile based scrolling
Thanks for explaining that kikito, so if I have a resolution of 320x180 it will be fine as long as all of my images are po2 safe?
Edit: I also just noticed that I "edited" one of my post's earlier, though when I submitted it, it submitted it as a different post. Very odd.
Edit: I also just noticed that I "edited" one of my post's earlier, though when I submitted it, it submitted it as a different post. Very odd.
Last edited by Ryne on Fri Dec 17, 2010 5:18 am, edited 1 time in total.
@rynesaur
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: Tile based scrolling
Yup.Ryne wrote:Thanks for explaining that kikito, so if I have a resolution of 320x180 it will be fine as long as all of my images are po2 safe?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Tile based scrolling
I looked at it, and it should work. Are you changing the player position somewhere else?Ryne wrote:Anyway, I don't want to get my thread sidetracked so in case Robin comes back please check the previous page for the reply to your question
Help us help you: attach a .love.
Re: Tile based scrolling
I checked my code. I don't think that the player position changes EVER (except for when he jumps, and even then its only y, not x). Player.x is declared in player.lua as x=130. The keyboard controls only move the map.Robin wrote:I looked at it, and it should work. Are you changing the player position somewhere else?Ryne wrote:Anyway, I don't want to get my thread sidetracked so in case Robin comes back please check the previous page for the reply to your question
Code: Select all
if love.keyboard.isDown('right') then
curranim = anim.runright
player.dir = "right"
map_x = map_x + 100 * dt
elseif love.keyboard.isDown('left') then
curranim = anim.runleft
player.dir = "left"
map_x = map_x - 100 * dt
end
Code: Select all
-- this in love.update, after the player position is changed:
map_x = player.x
map_y = player.y
Code: Select all
for i=1, #enemies do
enemies[i].anim:draw(enemies[i].x - map_x, enemies[i].y)
end
... this is frustrating. Thanks again for the reply.
@rynesaur
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Tile based scrolling
You're nearly there, but you're not seeing one thing.
You are changing the variable map_x when the player moves. I see two options:
You are changing the variable map_x when the player moves. I see two options:
- Discard map_x altogether, use player.x in places map_x was used previously. Remember to draw the player at the right position.
- Use player.x in the updating code, and map_x in drawing code. Set map_x to player.x at the end of love.update. This might be useful if you want to do cutscenes ore the like later on.
Help us help you: attach a .love.
Re: Tile based scrolling
Thanks for the reply, but I'm still really confused by what you mean by BOTH of those options.
I'm sorry if this is easier than I'm making it, though I'm still confused..
when you say "use player.x in places map_x was previously used" do you mean everywhere? Including the map draw code? What do you mean by "Remember to draw the player at the right position"?Discard map_x altogether, use player.x in places map_x was used previously. Remember to draw the player at the right position.
You mean remove player.x from my player table (located in player.lua) into my game update?Use player.x in the updating code, and map_x in drawing code. Set map_x to player.x at the end of love.update. This might be useful if you want to do cutscenes ore the like later on.
I'm sorry if this is easier than I'm making it, though I'm still confused..
@rynesaur
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Tile based scrolling
Yes. It was about banishing map_x and using player.x instead.Ryne wrote:when you say "use player.x in places map_x was previously used" do you mean everywhere? Including the map draw code?
Well, of the top of my head I'm not sure what would happen, but it is very possible that it would wreak havoc on your drawing code, so I thought I'd prepare you for that. Unfortunately, I was being very vague.Ryne wrote:What do you mean by "Remember to draw the player at the right position"?
No, I mean a conceptual split: player.x represents the true position of the player, like enemies[1].x represents the true position of the 1st enemy. map_x represents the offset at which things are drawn, the position in the real world that is drawn at (0, 0).Ryne wrote:You mean remove player.x from my player table (located in player.lua) into my game update?
No worries, we'll figure this out.Ryne wrote:I'm sorry if this is easier than I'm making it, though I'm still confused..
Help us help you: attach a .love.
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot], xxl and 217 guests