I'm creating a sidescroller where the "camera" follows the player. I am setting the drawOffset in my updated loop after the player moves.
gfx.setDrawOffset(offsetX, offsetY)
I have a tilemap I set to the background. The following code works just fine for drawing the background, but it draws the entire tilemap:
gfx.sprite.setBackgroundDrawingCallback(
function( x, y, width, height )
tilemap:draw(offsetX, offsetY)
end
)
How do I get the tileMap to only draw the visible part on the screen? I've tried the following code and it produces erratic results where the background is shifted and scrolls super fast.
gfx.sprite.setBackgroundDrawingCallback(
function( x, y, width, height )
tilemap:draw(offsetX, offsetY, -offsetX + x, -offsetY + y, width, height)
end
)
I can't seem to find any good documentation on how to draw the tilemap in the background as just the visible part of the tilemap. Is there some translation between tile coordinates and world coordinates I'm missing? Any help would be greatly appricated! Thanks!