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
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Tile based scrolling

Post by Ryne » Sat Dec 18, 2010 12:28 am

Robin wrote: No worries, we'll figure this out.
Alright so, which method would you consider the best? (or more efficient)?
@rynesaur

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Tile based scrolling

Post by kikito » Sat Dec 18, 2010 12:32 am

I'd suggest not using player.x or map_x, and just doing love.graphics.translate(-player.x, -player.y).
When I write def I mean function.

User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Tile based scrolling

Post by Ryne » Sat Dec 18, 2010 12:33 am

kikito wrote:I'd suggest not using player.x or map_x, and just doing love.graphics.translate(-player.x, -player.y).
I'm already beyond confused with this whole deal. :(

@Robin, So I've been playing with my code for about an hour now and have gotten nowhere, apparently I'm still not quite understanding what you're suggesting.. I understand you're busy, So whenever you get some time would you mind giving me a hand?

Thank's again guys.
@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 » Sat Dec 18, 2010 8:54 am

Ryne wrote:Alright so, which method would you consider the best? (or more efficient)?
What the best method is depends on what you want. If you want flexibility, and maybe use in-game cutscenes or things like that in the future, it's probably better to use one variable to keep track of the player location and another for the "camera" position (for which you can use love.graphics.translate if you want, but let's not get into that yet). But it's (slightly) simpler to make it all the same variable. So it depends on what you want, really.
Ryne wrote:@Robin, So I've been playing with my code for about an hour now and have gotten nowhere, apparently I'm still not quite understanding what you're suggesting.. I understand you're busy, So whenever you get some time would you mind giving me a hand?
Starting today I have a vacation, so I have lots of time. There are things I have to do as well, but the vacation makes it flexible. I think the largest obstacle could be differing time zones.

If you want, I could give you code instead of just talking about it, maybe that helps. I won't drop it all on you, but find some way that works better.
Help us help you: attach a .love.

User avatar
Xkeeper
Prole
Posts: 40
Joined: Wed Aug 04, 2010 2:49 am
Location: Henderson, Nevada, US
Contact:

Re: Tile based scrolling

Post by Xkeeper » Sat Dec 18, 2010 10:23 am

Ryne wrote:
Robin wrote: Then why don't you change the player position? That is much less work for the computer than updating every enemy, just when the player moves.
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?
Late, but the way I do all of my stuff, is:

- Have a specific "camera x/y" variable, for the top left (or whatever) of the view
- Have the map's origin be, say, camera position 0,0
- Consider the player's movement to always be based off of the map, not the screen; same with any objects, enemies, or other text
- When actually drawing, offset all on-screen objects by camera_x and camera_y, optionally ignoring aything that works out to be outside the screen

Though for something pre-written, it may be kind of hard to update...

User avatar
Ryne
Party member
Posts: 444
Joined: Fri Jan 29, 2010 11:10 am

Re: Tile based scrolling

Post by Ryne » Sat Dec 18, 2010 5:41 pm

Robin wrote: If you want, I could give you code instead of just talking about it, maybe that helps. I won't drop it all on you, but find some way that works better.
Some code might be helpful since I think I'm doing what I normally do, and over-complicating things, but I'm still not going to use code I understand. If you post anything I might ask some pretty specific questions, just so I know exactly what's happening. My only issue with someone posting code is if It's not explained.

Pretty much at this point in time the map code seems to be working correctly. Meaning the map scrolls fine, the player seems to move fine, and the enemies seem to move fine.

This includes having the player controls use map_x instead of player.x, and the enemies are drawn like this:

Code: Select all

	for i=1, #enemies do			 
		enemies[i].anim:draw(enemies[i].x - map_x, enemies[i].y)
	end
So it just seems like there is some tiny piece of code messing something up. I've already posted my "player follow code" a bunch of times. It, as well as almost all of my functions work off x/y variables, should some of these be modified to include map_x or something?

Thanks Robin. (I think I should just add "Thanks Robin" to my signature, it's probably the 2 words I use the most)
@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 » Sat Dec 18, 2010 10:55 pm

Ryne wrote:So it just seems like there is some tiny piece of code messing something up. I've already posted my "player follow code" a bunch of times. It, as well as almost all of my functions work off x/y variables, should some of these be modified to include map_x or something?
Is the .love up on dropbox the most recent one? It's a bit late right now, but I could look at it tomorrow.
Ryne wrote:Thanks Robin. (I think I should just add "Thanks Robin" to my signature, it's probably the 2 words I use the most)
:nyu: You're welcome.
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 » Sat Dec 18, 2010 10:57 pm

Robin wrote:
Ryne wrote:So it just seems like there is some tiny piece of code messing something up. I've already posted my "player follow code" a bunch of times. It, as well as almost all of my functions work off x/y variables, should some of these be modified to include map_x or something?
Is the .love up on dropbox the most recent one? It's a bit late right now, but I could look at it tomorrow.
Yupp, that's the most recent one. Thanks again.
@rynesaur

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests