Page 67 of 92

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Wed Jan 18, 2017 11:10 am
by adekto
hi im trying to use this but im not sure how to add tile collision in the game (used tile collision editor window)
its problematic dealing with slopes right now ...

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Fri Jan 20, 2017 8:43 pm
by Karai17
Check the documentation for the "box2d" plugin. You need to set your tiles, objects, or layers to have the custom property "collidable" with a boolean value of "true".

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Sat Jan 21, 2017 2:43 pm
by sefan
Hi, Just started developing a roguelike game. And i have some questions about STI.
It's possible to rotate or invert a map?
And is it possible to change color of a map, like changing the RGB for it? Or change the tileset?

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Sat Jan 21, 2017 7:12 pm
by Karai17
What do you mean by invert?

It should be possible to rotate the map:

Code: Select all

function love.draw()
   love.graphics.push()
   love.graphics.rotate(math.pi)
   map:draw()
   love.graphics.pop()
end
You can use love.graphics.setColor before drawing the map to multiply a colour over the map.

You cannot change the tileset easily, but it is possible if you *really* want to.

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Sat Jan 21, 2017 7:16 pm
by 4aiman
Karai17 wrote:Check the documentation for the "box2d" plugin. You need to set your tiles, objects, or layers to have the custom property "collidable" with a boolean value of "true".
Boolean value didn't work for me. A string one did. (I've started with Tiled 0.9.something and STI 0.14.1.13)
sefan wrote:And is it possible to change color of a map, like changing the RGB for it?
This may be ineffective, but I've implemented color change by editing some STI's internals:

Code: Select all

-- http://stackoverflow.com/a/7615129
function mysplit(inputstr, sep)
        if sep == nil then
                sep = "%s"
        end
        local t={} ; i=1
        for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
                t[i] = str
                i = i + 1
        end
        return t
end

--- Batch Tiles in Object Layer for improved draw speed
-- @param layer The Object Layer
-- @return nil
function Map:setObjectSpriteBatches(layer)
	local newBatch = love.graphics.newSpriteBatch
	local tw       = self.tilewidth
	local th       = self.tileheight
	local batches  = {}

	for _, object in ipairs(layer.objects) do
		if object.gid then
			local tile  = self.tiles[object.gid] or self:setFlippedGID(object.gid)
			local ts    = tile.tileset
			local image = self.tilesets[tile.tileset].image

			batches[ts] = batches[ts] or newBatch(image, 1000)

			local batch = batches[ts]
			local tx    = object.x + tw + tile.offset.x
			local ty    = object.y + tile.offset.y
			local tr    = math.rad(object.rotation)
			local oy    = 0

			-- Compensation for scale/rotation shift
			if tile.sx == 1 and tile.sy == 1 then
				if tr ~= 0 then
					ty = ty + th
					oy = th
				end
			else
				if tile.sx < 0 then tx = tx + tw end
				if tile.sy < 0 then ty = ty + th end
				if tr      > 0 then tx = tx + tw end
				if tr      < 0 then ty = ty + th end
			end

         local props = object.properties or {}
         if props.color then            
            batch:setColor(mysplit(props.color, ","))
         else
            batch:setColor(255,255,255)
         end 
			id = batch:add(tile.quad, tx, ty, tr, tile.sx, tile.sy, 0, oy)
			self.tileInstances[tile.gid] = self.tileInstances[tile.gid] or {}
			table.insert(self.tileInstances[tile.gid], {
				layer = layer,
				batch = batch,
				id    = id,
				gid   = tile.gid,
				x     = tx,
				y     = ty,
				r     = tr,
				oy    = oy
			})
		end
	end

	layer.batches = batches
end
This works for object layer only, but can be used to add similar feature to any layer.
However, RGB is not something you (probably?) want. Look for some articles regarding HSV hue shift: http://stackoverflow.com/questions/8507 ... -rgb-color
The difference?
RGB coloring
RGB coloring
Thursday December 2016 @ 22_54_22.png (52.14 KiB) Viewed 5836 times
HSV shift
HSV shift
Monday January 2017 @ 00_39_26.png (431.18 KiB) Viewed 5836 times
sefan wrote:Or change the tileset?
The easiest thing to do in order to change the tileset is to have a separate map file with different tileset in the code:

Code: Select all

  tilesets = {
    {
      name = "turbulence",
      firstgid = 1,
      tilewidth = 32,
      tileheight = 32,
      spacing = 0,
      margin = 0,
      image = "<HERE GOES YOUR TILESET>",
      imagewidth = 128,
      imageheight = 32,
      ...
Guess it can be done "on-the-fly" if you read from the map file into some variable and just string.gsub the path.

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Sat Jan 21, 2017 7:19 pm
by Karai17
Why use such old versions? Upgrade to the latest Tiled and STI!

Since tiled maps are just lua files, you don't need to "read" them at all. you can use love.filesystem.load to load them as lua wrapped in a function, so when you execute it you can jus tplace the map into a variable since it is just a big table. Fro mther eyou can just directly access the string holding the tileset and rpelace it with whatever tileset you want.

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Sat Jan 21, 2017 7:45 pm
by 4aiman
Karai17 wrote:Why use such old versions? Upgrade to the latest Tiled and STI!
I've *started* with those :)
I'm using latest-dev Tiled as of now (doesn't really matter, since the official build is not that old).
As for STI... I haven't had any problems with it (except that 1000 typo), so never felt like upgrading.
Karai17 wrote:...you can jus tplace the map into a variable...
... directly access the string holding the tileset and rpelace it with whatever tileset you want.
I was telling the same... Now, was I? :?
Guess at least it looked like I wasn't. :(


Edit:
Checked the STI commit list... Not so sure I should update while so in-core-dev of my project...
Guess I may have some workarounds I don't really know about which will turn into issues after an upgrade.

Re: Simple Tiled Implementation - STI v0.16.0.3

Posted: Sat Jan 21, 2017 9:22 pm
by sefan
Thanks Karai17 and 4aiman :awesome:
Karai17 wrote:What do you mean by invert?
Invert was wrong word. I mean flip the map. So left side becomes the right side but top and bottom side stays. Or bottom side becomes top side but left and right side stays.
4aiman wrote:This works for object layer only, but can be used to add similar feature to any layer.
However, RGB is not something you (probably?) want. Look for some articles regarding HSV hue shift: http://stackoverflow.com/questions/8507 ... -rgb-color
Think that is more what i was looking for.

Re: Simple Tiled Implementation - STI v0.18.1.0

Posted: Wed Feb 01, 2017 9:20 pm
by Karai17
I added several bug fixes and features. STI should now be in line with Tiled 0.18.1. Most notable change is that Map.drawRange has been removed. Instead of creating tile batches, I just use a single batch for each layer, no culling necessary. A potential rendering bug in staggered and hexagonal maps has also been fixed, and the issue with collision objects being incorrectly offset when offsetting maps should now be fixed as well.

Re: Simple Tiled Implementation - STI v0.18.1.0

Posted: Wed Feb 01, 2017 9:49 pm
by raidho36
You shouldn't have removed it. Instead, you should've added an option to draw entire layer as a single batch. On some computers, rendering hundreds of thousands of sprites may be extremely slow and only rendering a few hundred would be a serious improvement.