Confused about how to use object layers with dusk

I would figure object layers would just present me with an x,y and my custom properties so that I can build objects out of them.  but i notice dusk creates an outline that looks more or less like the rectangle i drew in tiled.

8UhuNvC.png?1

so i saw this and i figured i just change the properties of it… but its not quite a rect is it?  it doesnt seem to have contentBounds or x and y.  Not sure what im dealing with here.  I guess what I want to do is get rid of this and add my own image object.  Caleb?

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?

VdNo72c.png?1

okay so 

dusk.setPreference("virtualObjectsVisible", false)

hides the virtual objects.  great.

next problem.  i’m calculating platform position on every frame.  when i leave the screen theyre deleted.  if i get rid of the code that removes the platforms and then i come back.  i have double platforms.  i want to disable culling for my object layer.  how do i do that?

okay… so i ditch all the object creation code and i just do this.

man i went around in a few circles here

 for object in map.layer["platform"].nameIs("moving") do local platform = display.newRect(0, 0, object.width, object.height) platform.x, platform.y = object.x, object.y platform.lastPos = {x=object.x, y=object.y} map.layer["platform"]:insert(platform) platformMovement(platform) platforms[#platforms+1] = platform end

Object culling kicks in whenever the host object goes outside the screen. So for moving platforms in my game, I make my host object the full width of the moving platform’s area. Then I build the moving platform as smaller than the host object and make it go within the host object’s bounds. That way, it’s also a lot clearer in the level editor, because you can specify each moving platform’s bounds visually.

  • Caleb

cool.  interesting idea.  ill prob stick without culling in the short term but thats a nice way of implementing it for a moving object

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?

VdNo72c.png?1

okay so 

dusk.setPreference("virtualObjectsVisible", false)

hides the virtual objects.  great.

next problem.  i’m calculating platform position on every frame.  when i leave the screen theyre deleted.  if i get rid of the code that removes the platforms and then i come back.  i have double platforms.  i want to disable culling for my object layer.  how do i do that?

okay… so i ditch all the object creation code and i just do this.

man i went around in a few circles here

 for object in map.layer["platform"].nameIs("moving") do local platform = display.newRect(0, 0, object.width, object.height) platform.x, platform.y = object.x, object.y platform.lastPos = {x=object.x, y=object.y} map.layer["platform"]:insert(platform) platformMovement(platform) platforms[#platforms+1] = platform end

Object culling kicks in whenever the host object goes outside the screen. So for moving platforms in my game, I make my host object the full width of the moving platform’s area. Then I build the moving platform as smaller than the host object and make it go within the host object’s bounds. That way, it’s also a lot clearer in the level editor, because you can specify each moving platform’s bounds visually.

  • Caleb

cool.  interesting idea.  ill prob stick without culling in the short term but thats a nice way of implementing it for a moving object