[SOLVED] Problem with "Simple Tiled Implementation" and love.graphics.tanslate (and scale)

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
LuaIsLife
Prole
Posts: 12
Joined: Fri Nov 02, 2018 4:48 pm

[SOLVED] Problem with "Simple Tiled Implementation" and love.graphics.tanslate (and scale)

Post by LuaIsLife »

Hello,

I'm trying to implement STI (Simple Tiled Implementation) in my code.. but I have a problem with the tutorial code
when it comes to the "love.graphics.scaling" and "love.graphics.translate" parts at the end of the tutorial (to keep the player centered to screen while
scrolling the level around).

https://github.com/karai17/Simple-Tiled ... -to-sti.md

Everything works.. except the "scaling und translating" parts.

In other words: My program just seems to ignore the lines with "scale" and "translate" ..

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 player = map.layers["Sprites"].player
	local tx = math.floor(player.x - screen_width  / 2)
	local ty = math.floor(player.y - screen_height / 2)


  	-- Transform world
	love.graphics.scale(scale)
	love.graphics.translate(-tx, -ty)
  
	-- Draw world
	map:draw()
	
end
.. alltogether.. no error, nothing, player and map (level) are fine otherwise, but the player sprite is moving around
like there is no translate active (and is leaving the window of course if it gets outside the boundaries)

The code is pretty much "copy & paste" from the tutorial, some lines adapted to different asset names, but that's it..

Any ideas where I might search for the problem?
Last edited by LuaIsLife on Sat May 04, 2019 7:54 pm, edited 1 time in total.
LuaIsLife
Prole
Posts: 12
Joined: Fri Nov 02, 2018 4:48 pm

Re: Problem with "Simple Tiled Implementation" and love.graphics.tanslate (and scale)

Post by LuaIsLife »

Update:

.. well, looking into the source code of "STI" I'm guessing that map:draw() seems to invalidate any love.graphics.scale oder .translate actions.. but you can pass the translate and scale params directly now ..

Code: Select all

--- Draw every Layer
-- @param tx Translate on X
-- @param ty Translate on Y
-- @param sx Scale on X
-- @param sy Scale on Y
function Map:draw(tx, ty, sx, sy)
(...)
.. and THEN it will work.

Seems the tutorial ist somewhat outdated.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 192 guests