Simple Tiled Implementation - STI v1.2.3.0

Showcase your libraries, tools and other projects that help your fellow love users.
KyleFlores1014
Citizen
Posts: 73
Joined: Thu May 25, 2017 1:43 pm

Re: Simple Tiled Implementation - STI v0.16.0.3

Post by KyleFlores1014 »

straydogstrut wrote: Tue Oct 04, 2016 9:43 am Thanks Karai,

No worries, I realised putting my query on the end of this topic might mean it would be buried.. but I thought it might end up being useful to others.

Thanks for clarifying. I think that's where I was getting confused. As you said, the only thing your plugin is concerned with is the collidable property exported from Tiled. Everything else I was trying to do with other types of collisions is outside of that and really is what Bump is concerned with. I've managed to handle both cases a bit cleaner in the following code:

Code: Select all

-- override playerFilter function
local playerFilter = function(item, other)
	
local kind

	-- if the object of the collision has a properties table 
	-- (ie. it's been exported from Tiled with the collidable custom property)
	if other.properties ~= nil then
		kind = other.properties -- store a reference to the properties table to use with the filter
	else
		kind = other.name -- else store a reference to the object's name since it has no properties table 
					    -- (useful as we can set the 'name' manually or grab it from the object exported by Tiled)
	end
	
	if kind.collidable then -- if object.properties table has the collidable element
		return 'slide'
	elseif kind == 'spring' then -- if object.name is spring
		return 'bounce'
	elseif kind == 'hotspot' then -- if object.name is hotspot
		return 'cross'
	end
end -- end of playerFilter function

-- actually move the player, obeying collisons
player.x, player.y, cols, len = world:move(player, player.x, player.y, playerFilter)
I was following this. Its at page 62 and 63. After bump:init the property disappears or unimportant anymore? Im confused (Sorry)
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by Karai17 »

I'll be honest, I don't really know much about bump, I didn't write the bump plugin it was sent via a PR. Perhaps you could pm the author of bump and see if they can help?
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
meleeman
Prole
Posts: 5
Joined: Mon Apr 30, 2018 7:46 am

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by meleeman »

How would I know if the STI program is actually creating box 2d objects? i seem to be having a problem detecting collisions using your loader. perhaps the implementation is off or something, or i did something wrong in tiled, but i'm considering writing my own collision detections. at first I thought it was a scope issue but now i'm not so sure. i used the example code of creating a sprite layer for my character and enemy to exist in, and i've attempted to make them box2d objects, and i got it to where I had no compile errors, but i don't see them bounce off eachother like i would expect in my box2d working example. could you help me out?
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by Karai17 »

Are you enabling the box2d plugin and initializing it?
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
KyleFlores1014
Citizen
Posts: 73
Joined: Thu May 25, 2017 1:43 pm

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by KyleFlores1014 »

(Sorry for interrupting) I just figured it out. I made an object layer and individual putted a custom property and that seem to have solved it.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by Karai17 »

Huzzah! I'm glad you figured it out. :)
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
meleeman
Prole
Posts: 5
Joined: Mon Apr 30, 2018 7:46 am

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by meleeman »

Karai17 wrote: Mon Apr 30, 2018 9:56 am Are you enabling the box2d plugin and initializing it?
i think so, i followed the implementation from the github page for the most part.

Code: Select all

--GAME STATES
menu = {} -- previously: Gamestate.new()
options = {}
game = {}
local win = {}
local lose = {}

--GAMESTATES-----------------------------------------------------------------------------
require "states.options"
require "states.menu"

local map
local world
local tx, ty



function love.load()
	map = sti("tests/testmap.lua", { "box2d" })
	-- Print versions
	print("STI: " .. sti._VERSION)
	print("Map: " .. map.tiledversion)
	print("ESCAPE TO QUIT")
	print("SPACE TO RESET TRANSLATION")
	-- Prepare translations
	tx, ty = 0, 0

	-- Prepare physics world
	love.physics.setMeter(40)
	world = love.physics.newWorld(0*love.physics.getMeter(), 0*love.physics.getMeter())
	map:box2d_init(world)
	--set up Gamestates
    Gamestate.registerEvents()
    Gamestate.switch(menu)
	map:addCustomLayer("Sprite Layer", 2)
	-- Add data to Custom Layer
	spriteLayer = map.layers["Sprite Layer"]
	spriteLayer.sprites = {
		npc1 = {
			name="testNPC",
			image = love.graphics.newImage("Assets/player.png"),
			x = 1064,
			y = 1094,
			r = 0,
			height=40,
			width=40
			
		},
		enemy1={
			name="testEnemy",
			x=1164,
			y=1164,
			r=0,
			height=20,--hitbox y
   			width=20,--hitbox x
			image= love.graphics.newImage("Assets/enemy.png"),
			body=love.physics.newBody(world,1164,1164,"dynamic"),
			shape=love.physics.newCircleShape(20),


		},
		player={
			name="Voice",
   			Health=5,
   			x=love.graphics.getWidth()/2,
   			y=love.graphics.getHeight()/2,
   			Speed=2, --movement speed
   			height=20,
   			width=20,
   			--box2d physics
   			phVoice=love.physics.newBody(world,love.graphics.getWidth()/2,love.graphics.getHeight()/2,"dynamic"),--set x,y position and let it move and hit other objects ("dynamic")
   			--setting mass???
   			phShape=love.physics.newCircleShape(20),--give it a radius of 20
   			--connect body to shape
   			--make it bouncy lol
   			

   			zIndex=3 --for each map/dungeon there is 3 levels. unless james says otherwise

		}
		
	}
	
	spriteLayer.sprites.player.phFixture=love.physics.newFixture(spriteLayer.sprites.player.phVoice,spriteLayer.sprites.player.phShape)
	spriteLayer.sprites.player.phFixture:setRestitution(4)
	spriteLayer.sprites.player.phFixture:setUserData("Voice")
spriteLayer.sprites.player.fixture=love.physics.newFixture(spriteLayer.sprites.enemy1.body,spriteLayer.sprites.enemy1.shape,2)

	--//////////////////////////////////////////WHERE I LEFT OFFF^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


	-- Update callback for Custom Layer
	function spriteLayer:update(dt)

		for _, sprite in pairs(self.sprites) do
			
--/////////////////////////////PLAYER ONE!!!!///////////////////////////////////////////////////////////////////////////////
			if sprite.name=="Voice" then
				-- below is movement
				local kd = love.keyboard.isDown
				
					if kd("left") or kd("a")then
					sprite.x=sprite.x-128*dt
					end
					if kd("right")or kd("d")then
					sprite.x=sprite.x +128*dt
					end
					if kd("up")or kd("w")then
					sprite.y=sprite.y -128*dt		
					end
					if kd("down") or kd("s")then
					sprite.y=sprite.y +128 *dt		
					end
			

				
			end
--/////////////////////////////END OF PLAYER ONE--//--/--/---//--/--//--//--//--//--//--//--////////////////////////////////
			if sprite.name=="testEnemy" then
			 
			sprite.r = sprite.r + math.rad(90 * dt)
			end
			
		end
		--CheckCollision(spriteLayer.sprites.player,spriteLayer.sprites.enemy1)
	end

	-- Draw callback for Custom Layer
	function spriteLayer:draw()
		for _, sprite in pairs(self.sprites) do
			local x = math.floor(sprite.x)
				local y = math.floor(sprite.y)
			if sprite.name=="testEnemy" then
				
				local r = sprite.r
				love.graphics.draw(sprite.image, x, y, r)
			end
			--this code will bite me in the ass later.
			-- code is in a master draw function, should be called
			if sprite.name=="Voice" then
			love.graphics.circle("fill",sprite.x,sprite.y,sprite.height)
			end

		end
	end


   	--this object is global, yet the physics don't work with the world physics???		 
	player1={
			name="Voice",
   			Health=5,
   			Xpos=love.graphics.getWidth()/2,
   			Ypos=love.graphics.getHeight()/2,
   			Speed=2, --movement speed
   			height=20,--hitbox y
   			width=20,--hitbox x
   			zIndex=3, --for each map/dungeon there is 3 levels. unless james says otherwise
   			phVoice=love.physics.newBody(world,love.graphics.getWidth()/2,love.graphics.getHeight()/2,"dynamic"),--set x,y position and let it move and hit other objects ("dynamic")
   			--setting mass???
   			phShape=love.physics.newCircleShape(20)--give it a radius of 20

		}
   			function game:update(dt)
	local kd = love.keyboard.isDown
			
	

	------------------------------------------map
	--world:update(dt)
	map:update(dt)

	-- Move map
	
	local l  = kd("left")  or kd("a")
	local r  = kd("right") or kd("d")
	local u  = kd("up")    or kd("w")
	local d  = kd("down")  or kd("s")

	tx = l and tx - 128 * dt or tx
	tx = r and tx + 128 * dt or tx
	ty = u and ty - 128 * dt or ty
	ty = d and ty + 128 * dt or ty

	
   
end

function game:draw()

   love.graphics.print("Hello World!!!")
  

   -- Draw map
	love.graphics.setColor(255, 255, 255)
	map:draw(-tx, -ty)

	-- Draw physics objects
	love.graphics.setColor(255, 0, 255)
	map:box2d_draw(-tx, -ty)

	love.graphics.circle("fill",player1.phVoice:getX(),player1.phVoice:getY(),player1.phShape:getRadius())
	
 
 
end
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by Karai17 »

In Tiled, are you creating layers or objects with a property called "collidable" and setting the value to a boolean true?
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
meleeman
Prole
Posts: 5
Joined: Mon Apr 30, 2018 7:46 am

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by meleeman »

i did. but i also set the property sensor as true as well. that could be the issue. i'll re-export the map.
meleeman
Prole
Posts: 5
Joined: Mon Apr 30, 2018 7:46 am

Re: Simple Tiled Implementation - STI v0.18.2.1

Post by meleeman »

no change
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests