Simple Tiled Implementation - STI v1.2.3.0

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
adekto
Prole
Posts: 35
Joined: Thu Dec 06, 2012 11:42 am

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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 ...
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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".
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
sefan
Prole
Posts: 23
Joined: Fri Jul 31, 2015 7:03 am
Contact:

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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?
Sefan.se GitHub.com Itch.io
Looking for help on graphics/music/sound effects. PM me if interested.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
4aiman
Party member
Posts: 262
Joined: Sat Jan 16, 2016 10:30 am

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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 5966 times
HSV shift
HSV shift
Monday January 2017 @ 00_39_26.png (431.18 KiB) Viewed 5966 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.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
4aiman
Party member
Posts: 262
Joined: Sat Jan 16, 2016 10:30 am

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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.
User avatar
sefan
Prole
Posts: 23
Joined: Fri Jul 31, 2015 7:03 am
Contact:

Re: Simple Tiled Implementation - STI v0.16.0.3

Post 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.
Sefan.se GitHub.com Itch.io
Looking for help on graphics/music/sound effects. PM me if interested.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.1.0

Post 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.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Simple Tiled Implementation - STI v0.18.1.0

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests