Advanced Tiled Loader - No longer maintained

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Advanced Tiled Loader

Post by bartbes »

arbaces wrote:I know that double posting is super evil and bartbes is going to kick my butt, but here I go...
Then why? You could've easily edited the previous post!
arbaces wrote: - If you set global.scale to values which aren't integer numbers divided by five, then there are sometimes horizontal and vertical lines. I assume these are seams because the ground's tiles aren't being scaled to the exact number of pixels needed, but I don't understand some of the logic in ATL yet. Is it possible to adjust the code such that the tiles won't have these seams?
That's because the images end up at non-integer x and/or y, you could try flooring them in their draw call.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Advanced Tiled Loader

Post by Nixola »

Kadoba wrote:
arbaces wrote: For 0.8.0 compatibility, on line 58 of main.lua, I think love.event.push('q') should be changed to love.event.push('quit').
Thanks. I'll get this fixed tomorrow.
You can change it to

Code: Select all

(love.event.push or love.event.quit)('q')
--Credits: someone who I don't remember >.< I think it was Bartbes or Robin, though
to have compatibility with both 0.8 and 0.7.2
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Advanced Tiled Loader

Post by coffee »

Nixola wrote:
Kadoba wrote:
arbaces wrote: For 0.8.0 compatibility, on line 58 of main.lua, I think love.event.push('q') should be changed to love.event.push('quit').
Thanks. I'll get this fixed tomorrow.
You can change it to

Code: Select all

(love.event.push or love.event.quit)('q')
--Credits: someone who I don't remember >.< I think it was Bartbes or Robin, though
to have compatibility with both 0.8 and 0.7.2
Perhaps was kikito (and Robin)?
viewtopic.php?f=4&t=8641&p=53276&hilit=love.quit#p53186
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Advanced Tiled Loader

Post by Nixola »

It was that topic, but the way I preferred (and wrote) is Robin's one
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
arbaces
Prole
Posts: 6
Joined: Sun Mar 25, 2012 6:44 pm

Re: Advanced Tiled Loader

Post by arbaces »

arbaces wrote:
I know that double posting is super evil and bartbes is going to kick my butt, but here I go...
Then why? You could've easily edited the previous post!
Sorry, I didn't know I could edit posts after posting. >.<



Kadoba wrote:This sounds like it's the image filter. By default the image filter is set to linear which blurs the image when scaled. You probably want the filter to be set to nearest. Just set the image of the character image using image:setFilter("nearest", "nearest"). Or you can set this as the default filter by using love.graphics.setDefaultImageFilter("nearest","nearest").
Thanks so much! This fixed that problem.
Kadoba wrote:
Arbaces wrote:- If you set global.scale to values which aren't integer numbers divided by five, then there are sometimes horizontal and vertical lines. I assume these are seams because the ground's tiles aren't being scaled to the exact number of pixels needed, but I don't understand some of the logic in ATL yet. Is it possible to adjust the code such that the tiles won't have these seams?
That's not quite an ATL thing. Scaling is the culprit though. When you draw with decimal coordinates then the image isn't guaranteed to "fit" together. The easiest fix for this is to render what you want on a canvas at 1:1 scaling and then scale the canvas up and down.
Is there a reason that this canvas method isn't the default behavior of ATL?

If it's something you would include, but didn't want to spend time on, I can try to put something together. My initial attempts were lackluster:

When I set aside a small canvas, it works! but only draws the top left corner of the map. There is no horizontal or vertical black lines for any scale that I tried. (This is on my game which runs ATL 0.9.0 on a modified version of the desert map)

I then tried to set aside a large canvas (8192x8192). For some reason, when I boot the game with this, my macbook's mother board turns on the blinking warning lights/warning beep and the computer becomes unresponsive until forced to hard reboot... That's somewhat frightening.



This is what I do in particular:

At the top of the file:

Code: Select all

canvas = love.graphics.newCanvas()
DesertExample.draw():

Code: Select all

-- Called from love.draw()
function DesertExample.draw()

  -- Set sprite batches if they are different than the settings.
  map.useSpriteBatch = global.useBatch

  if map[currentMap] == nil then
    -- Cut out unimportant stuff here
    return
  end
  
  love.graphics.setCanvas( canvas )

  -- Limit the draw range 
  if global.limitDrawing then 
    map[currentMap]:autoDrawRange(ftx, fty, global.scale, -100) 
  else 
    map[currentMap]:autoDrawRange(ftx, fty, global.scale, 50) 
  end
	
  -- Queue our char to be drawn after the tile he's on and then draw the map.
  local maxDraw = global.benchmark and 20 or 1
  for i=1,maxDraw do 
    map[currentMap]:draw() 
  end

  love.graphics.setCanvas()

  -- Scale and translate the game screen for map drawing
  local ftx, fty = math.floor(global.tx), math.floor(global.ty)
  love.graphics.push()
  love.graphics.scale(global.scale)
  love.graphics.translate(ftx, fty)

  love.graphics.draw(canvas)
  canvas:clear()
		
  -- Reset the scale and translation.
  love.graphics.pop()
	
  if map[currentMap].filter ~= nil then
    love.graphics.draw(map[currentMap].filter)
  end
	  
  HUD.draw()
end

User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Advanced Tiled Loader

Post by Kadoba »

bartbes wrote:That's because the images end up at non-integer x and/or y, you could try flooring them in their draw call.
I don't know of a good way to do this with love.graphics.scale though. Even if the starting draw values are integer they might not be after the scaling applies.
arbaces wrote: Is there a reason that this canvas method isn't the default behavior of ATL?
Yes. Some hardware doesn't support canvases and there's multiple ways to go about it. Large canvases take up a lot of memory. If you get them large enough the evidently it can kill your video card. One solution might be to render sections to a smaller canvas and then draw each section to the screen. This would have the same tearing problem as ATL does with quads but you would be able to control the draw values after scaling so you could just floor them like bartbes said.
arbaces
Prole
Posts: 6
Joined: Sun Mar 25, 2012 6:44 pm

Re: Advanced Tiled Loader

Post by arbaces »

Thanks again for your response Kadoba. Would you recommend not using canvases then?

I got my canvas system working, though the degree to which one can zoom out is limited by the size of the canvas. Since my canvas has dimensions 4x as large as my screen, I can scale as low as 0.25. In case anyone is curious, my code is below (which is sloppy for now, but works):

Code: Select all

canvas = love.graphics.newCanvas(3200, 2400)
canvas:setFilter("nearest", "nearest")

Code: Select all

-- Called from love.draw()
function DesertExample.draw()

  -- Set sprite batches if they are different than the settings.
  map.useSpriteBatch = global.useBatch

  if map[currentMap] == nil then
    -- Snipped out irrelevant code here
    return
  end
  
  love.graphics.setCanvas(canvas)

  local ftx, fty = math.floor(global.tx), math.floor(global.ty)

  -- Limit the draw range 
  --if global.limitDrawing then 
  --  map[currentMap]:autoDrawRange(ftx, fty, global.scale, -100) 
  --else 
    map[currentMap]:autoDrawRange(ftx, fty, global.scale, 50) 
  --end
	
  love.graphics.push()
  love.graphics.translate(ftx, fty)

  -- Queue our char to be drawn after the tile he's on and then draw the map.
  local maxDraw = global.benchmark and 20 or 1
  for i=1,maxDraw do 
    map[currentMap]:draw() 
  end

  love.graphics.pop()

  love.graphics.setCanvas()

  -- Scale and translate the game screen for map drawing
  local ftx, fty = math.floor(global.tx), math.floor(global.ty)
  love.graphics.push()
  love.graphics.scale(global.scale)

  love.graphics.draw(canvas)
  canvas:clear()
		
  -- Reset the scale and translation.
  love.graphics.pop()

  -- Display movement instructions for a second
  if displayTime < displayMax then
    love.graphics.setColor(0,0,0,100)
    love.graphics.rectangle("fill",0,198,love.graphics.getWidth(),17)
    love.graphics.setColor(255,255,255,255)
    love.graphics.print("Use WASD to move me!", 330, 200)
  end
	
  if map[currentMap].filter ~= nil then
    love.graphics.draw(map[currentMap].filter)
  end
	  
  -- HUD display
  damageHandler.draw()
  HUD.draw()
end
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Advanced Tiled Loader

Post by Kadoba »

Canvases are fine. I would just avoid making them crazy big. Good to see you got it working. :)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Advanced Tiled Loader

Post by Robin »

Why I love this forum: getting attribution for a single line of code. ;)
Help us help you: attach a .love.
User avatar
Krizzu
Prole
Posts: 20
Joined: Sun Apr 15, 2012 8:02 pm

Re: Advanced Tiled Loader

Post by Krizzu »

How to avoid that black spaces, to make all windows with my tiles?

Code: Select all

function love.draw()

    map1:draw()

end
Attachments
1.png
1.png (13.31 KiB) Viewed 2418 times
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 68 guests