Hi guys, I'm working on a top-down 2d game. I need the camera to follow WASD controls and also zoom in and out, but I'm not sure how to do that. I am using STI to draw the tiled map. Can anyone help me out?
Thanks!
[STI] How to add map scrolling?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: [STI] How to add map scrolling?
This tutorial for STI shows how to make the camera follow a player (see the draw section at the bottom).
The tutorial is a bit outdated (see this comment by Karai17). The right way to do it is essentially something like this:
Would make the camera centered on player.x and player.y. Then you could change the 'scale' variable to zoom in and out.
The tutorial is a bit outdated (see this comment by Karai17). The right way to do it is essentially something like this:
Code: Select all
function love.draw()
-- Scale world
local scale = 2
local screen_width = love.graphics.getWidth() / scale
local screen_height = love.graphics.getHeight() / scale
-- Translate world so that player is always centred
local tx = math.floor(player.x - screen_width / 2)
local ty = math.floor(player.y - screen_height / 2)
-- Draw (different from tutorial)
map:draw(-tx, -ty, scale, scale)
end
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 3 guests