ok so i figured it out reading the other thread… things are mostly better. i still have problem. see bottom
in tiled i set the type property of my object to “moving” (im making moving platforms)
i copied this code in order to add the object to my tiled map
local function addObjectType(params) params.objects = params.objects or {} local function buildObject(event) local obj = params.build(event) event.object.builtObject = obj obj.mapObject = event.object params.objects[obj] = obj end for layer in map.objectLayers() do layer.addObjectListener("type", params.objectType, "drawn", buildObject) layer.addObjectListener("type", params.objectType, "erased", function(event) params.objects[event.object.builtObject] = nil params.remove(event.object.builtObject) end) end end
this is how my object is created. theres some custom functionality i omitted here to keep it clear. anyway this is mostly what caleb posted in his thread. tying it together was a little confusing. so hopefully this helps other people.
local movingPlatform = {} movingPlatform.objectType = "moving" -- A function which creates your custom object movingPlatform.build = function(event) local object = display.newRect(0, 0, event.object.width, event.object.height) object.x, object.y = event.object.x, event.object.y event.object.parent:insert(object) platforms[#platforms+1] = object -- i use this to keep track of the platforms return object end -- A function which deletes your custom object movingPlatform.remove = function(object) display.remove(object) end addObjectType(movingPlatform)
so now i have a moving platform… but i still have a leftover object stuck to the screen. do i need to just set that to invisible or what?
you see my platform has moved to the right, and underneath is the original object. kinda weird. why is that there and how should i get rid of it?