Fine tile scrolling with Tiled

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.
Post Reply
User avatar
qrux
Prole
Posts: 28
Joined: Thu Nov 03, 2011 1:11 am

Fine tile scrolling with Tiled

Post by qrux »

Hey,
i'm using Advanced Tiled Loader to load maps, and it's working great. However, i wanted the map to scroll when i moved and wrote this piece of code:

Code: Select all

  if love.keyboard.isDown("up", "w") then ty = ty + 250*dt 
  end
  if love.keyboard.isDown("right", "d") then tx = tx - 250*dt
  end
  if love.keyboard.isDown("left", "a") then tx = tx + 250*dt
  end
  if love.keyboard.isDown("down", "s") then ty = ty - 250*dt
  end
Unfortunately, that makes the player move one tile at a time :( How can i make it scroll "per pixel" instead? I looked up the "Fine Tile Scrolling" tutorial on the wiki but didn't really understand it.
My .love file is here: http://www.mediafire.com/?o92it7mpgp434ht

Thanks!
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Fine tile scrolling with Tiled

Post by Ellohir »

I use a camera and set the center into the player everytime it moves (the player can move one pixel at a time). Also, the camera has bounds on the map end so it doesn't show anything outside the map (the only way the player moves from the center of the screen). I use http://nova-fusion.com/2011/05/09/camer ... nt-bounds/

PS: Why the sound file? You don't play it and it's quite a big file.
User avatar
qrux
Prole
Posts: 28
Joined: Thu Nov 03, 2011 1:11 am

Re: Fine tile scrolling with Tiled

Post by qrux »

Ah, i see! Thanks!
Ellohir wrote:PS: Why the sound file? You don't play it and it's quite a big file.
I did use it in the past but i don't anymore, and never got around to deleting it. Done now though :)
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Fine tile scrolling with Tiled

Post by Kadoba »

Your movement actually is per-pixel. The blocky movement is a combination of love.graphics.scale() and flooring your love.graphics.translate() values. Since your pixels are 4x larger this will makes your screen move 4 pixels at a time. This is easier to see if you slow down your speed a lot. Instead of flooring your translation do this instead:

Code: Select all

local ftx, fty = tx - tx % (1/scale),  ty - ty %( 1/scale)
This is still flooring your values but in such a way that it will always move one pixel on your screen rather than the scaled up pixels.

I've reuploaded your game with the fix. You can change the scale with Q and E.
Attachments
game2.love
(455.8 KiB) Downloaded 133 times
User avatar
qrux
Prole
Posts: 28
Joined: Thu Nov 03, 2011 1:11 am

Re: Fine tile scrolling with Tiled

Post by qrux »

Kadoba wrote:Your movement actually is per-pixel. The blocky movement is a combination of love.graphics.scale() and flooring your love.graphics.translate() values. Since your pixels are 4x larger this will makes your screen move 4 pixels at a time. This is easier to see if you slow down your speed a lot. Instead of flooring your translation do this instead:

Code: Select all

local ftx, fty = tx - tx % (1/scale),  ty - ty %( 1/scale)
This is still flooring your values but in such a way that it will always move one pixel on your screen rather than the scaled up pixels.

I've reuploaded your game with the fix. You can change the scale with Q and E.
Thank you for your answer! Although, i have found that it was another problem that was causing this. I noticed the game was running at ~8 FPS, so i checked what was causing that and i found that i did not use Advanced Tiled Loader's

Code: Select all

map:autoDrawRange(tx, ty, scale, 7)
All that does is that it only does draw the map around you, not "infinitely".

However, i have implemented your fix too. Thanks!
Post Reply

Who is online

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