Page 41 of 92

Re: Simple Tiled Implementation - STI v0.14.1.8

Posted: Fri Dec 11, 2015 5:21 pm
by Rishavs
Hi

I seem to have hit an issue with your lib.

For isometric Staggered map, it is only displaying 21, 21 tiles.

I am attaching the map i used.

my code is here

https://github.com/rishavs/RoguishLove/

and the file where all the map stuff happens is src/_state_Game.lua

Re: Simple Tiled Implementation - STI v0.14.1.8

Posted: Mon Dec 21, 2015 9:40 pm
by giantofbabil
First off I love STI, you have made my life a hell of a lot easier, thank you!

Is there a way to get the edges of the map? I'd like to be able to restrict both camera and character movement to the map edges but don't know where to get the coordinates. I'm also a little unsure how I would program restricting the camera, my code for it is pretty much the same as the STI Demo:

Code: Select all

function drawLevel_01()
  --CAMERA CODE---------------------------------------------------------------------------------------------------
  --translation based on player's x/y
  local sprite = map.layers['Sprite Layer'].sprites.player
	local ww = love.graphics.getWidth()
	local wh = love.graphics.getHeight()
	tx = math.floor(-sprite.x + ww / 2 - 16)
	ty = math.floor(-sprite.y + wh / 2 + 100)

	-- Draw sprite in centre of screen
	love.graphics.push()
	love.graphics.translate(tx, ty)
	map:setDrawRange(-tx, -ty, ww, wh)
  
  --draw map and all objects within
  map:draw()
    
  --draw collision map (useful for debugging) comment out to get rid of collision boxes
  love.graphics.setColor(255, 0, 0, 255)
  love.graphics.polygon("line", sprite.body:getWorldPoints(sprite.shape:getPoints()))
  love.graphics.polygon("line", sprite.body:getWorldPoints(sprite.gShape:getPoints()))
  love.graphics.polygon("line", sprite.body:getWorldPoints(sprite.lwShape:getPoints()))
  love.graphics.polygon("line", sprite.body:getWorldPoints(sprite.rwShape:getPoints()))
  love.graphics.circle("line",sprite.x, sprite.y + 20, 38)
  map:box2d_draw()
  
  love.graphics.pop()
  
end

Re: Simple Tiled Implementation - STI v0.14.1.8

Posted: Mon Dec 21, 2015 10:37 pm
by giantofbabil
Haven't been able to test it with the top and right side of the map yet but I got it the camera to limit by putting this in the code in before love.graphics.push()

Code: Select all

  if tx > 0 then tx = 0 end
  if tx < -7680 + love.graphics.getWidth() then tx = -7680 + love.graphics.getWidth() end
  if ty > 0 then ty = math.floor(-sprite.y + wh / 2 + 100) end
  if ty < -4352 + love.graphics.getHeight() then ty = -4352 + love.graphics.getHeight() end
Where -7680 and -4352 are the negatives of the size of my map from Tiled in pixels :3

Re: Simple Tiled Implementation - STI v0.14.1.8

Posted: Mon Dec 21, 2015 10:41 pm
by Karai17
@Rishavs sorry for the late response. My computer is currently broken so I can't do much testing atm. Once I get a new power supply I'll take a look at your issue if you haven't already fixed it.

@giantofbabil Yeah you want to make sure that translate isn't going out of bounds

0 < translate < map_size_in_pixels - screen_size

Re: Simple Tiled Implementation - STI v0.14.1.8

Posted: Tue Dec 22, 2015 9:21 pm
by giantofbabil
Any idea how I can set a specific tile to change a variable in my code? I have a tile that is spikes for instance and I would like it to set a boolean called spikeDamage to true, but I'm not sure how to check if the player is touching a specific tile for anything other than collision(which I do by going custom properties in tiled and putting "collidable" in the left side and "true" in the right in Tiled). I tried just putting spikeDamage in left box and true in right box in Tiled but that doesn't work.

Re: Simple Tiled Implementation - STI v0.14.1.8

Posted: Tue Dec 22, 2015 9:26 pm
by Karai17
You can use the convert functions to convert between coordinate systems. In this case you want to convert the pixel value to tiles and then check that tile for whatever property.

Re: Simple Tiled Implementation - STI v0.14.1.8

Posted: Tue Dec 22, 2015 10:36 pm
by giantofbabil
Karai17 wrote:You can use the convert functions to convert between coordinate systems. In this case you want to convert the pixel value to tiles and then check that tile for whatever property.
Thanks! I ended up making a couple variables that track the players tile location so I can check that against whatever I need to going forward.

Re: Simple Tiled Implementation - STI v0.14.1.8

Posted: Thu Dec 24, 2015 5:35 pm
by Rishavs
@giant: you can check my bounds code at. I also discussed the same a couple of pages ago in the very thread.
https://github.com/rishavs/RoguishLove/

@Karai: no worries.
The weird thing is that if I define the

Code: Select all

self.map:setDrawRange(0, 0, windowWidth, windowHeight)
, then only 21*21 tiles are rendered.

If i comment it out, 21 tiles rendered widthwise, and then 21 more tiles are rendered on top of it (so it looks multiple sheets with the edges on top of each other). The tiles are rendered properly vertically.

Also, my camera bound code simply doesnt works for the right edge and bottom edge anymore. Not sure if it is relatd to the same "21" issue or something i need to change to handle staggered isometric maps (my bounding code works correctly for normal diamond shaped isometric maps)

Finally, happy holidays everyone!

Re: Simple Tiled Implementation - STI v0.14.1.8

Posted: Thu Dec 24, 2015 5:39 pm
by Karai17
Yeah my draw range cover doesn't work for anything besides ortho atm. Since no one seems to use anything else, it was never a priority for me.

Re: Simple Tiled Implementation - STI v0.14.1.8

Posted: Mon Dec 28, 2015 12:51 am
by premek
Hi,
thanks for this library. I have a question -- sorry if this has been asked already.
How can I easily implement "collecting" items from a map? For example I have a layer with "coin" or "key" tiles and if player collides with a tile in this layer I want to remove the tile from the layer (simply stop displaying that one).
Is this possible to programatically modify the loaded map or is it out of scope for this library?
What is a recommended or a common way to do this? Should I insert the objects into the map (custom layer?) from code and then remove them? (I probably know how to do this.) But I'd like better to use Tiled editor to insert collectible items into the map.

Thanks!