use culling but disable it for specific types of objects?

I am using object culling and its all working great. the problem is that I have some objects that i’d really prefer to create all at once.

 For example I have a set of spikes that go up and down at different intervals.  The timing is really important because it allows the player to time his jumps and avoid the spikes…

With culling their timing becomes unpredictable because theyre created as i encounter them.

 I noticed that with culling turned on iterating over an object layer only gives me what’s visible.  Is there any way to force dusk to give me information about objects that havent been culled so i can manually create my objects?

There are a couple of ways you could handle this:

1. Use an iterator and manually build objects.

There is an iterator to go through data (i.e. non-culled essence-of-object) with. It’s core and for power users, but it definitely exists. It’s called map.objDatas(). Once you’ve implemented the iterator, however, you’re kind of on your own… Dusk doesn’t provide a means to build objects outside of core. I recommend option 2 (below).

for data in map.layer["object layer"].objDatas() do -- 'data' will refer to each object's data stored in Dusk's core object data structure. -- Some things you might need to know about the structure: -- `data.type` = the type of object (viz. "rect", "ellipse", etc.) -- `data.transfer` = properties which will be set on the object when it's created. For example, this has `transfer.x` set to the object's final X position, `transfer.rotation` set to the rotation, etc. Anything you set in here will show up on the object when it's built. end

2. Use system time to sync object positions

This would be a good thing for future development, too, as it would allow you to implement better controls for objects’ timing. What I mean is to set some properties on your objects to denote “start cycle time”, “cycle length”, etc., then in your code sync the objects according to that. You can use Dusk’s addObjectListener function to specify objects with type = “spike” or something:

map.layer["object layer"].addObjectListener( "type", "spike", -- Listen for all objects with type = "spike" "drawn", -- Listen for when they're drawn function(event) local spike = event.object -- event.object is the object that was drawn -- Use this listener to sync the spike's position when it's created if spikeShouldBeUp(spike) then -- This function would take the spike's properties and tell whether, given the current time and the spike's properties, it should be up or down goUp(spike) -- STAB! (R.I.P Intrepid Adventurer.) else goDown(spike) -- Run for it! They're down! end -- Also, you probably won't need it, but event.name is the name of the event ("drawn" in this case) end )
  • Caleb

thanks for the help :slight_smile:

There are a couple of ways you could handle this:

1. Use an iterator and manually build objects.

There is an iterator to go through data (i.e. non-culled essence-of-object) with. It’s core and for power users, but it definitely exists. It’s called map.objDatas(). Once you’ve implemented the iterator, however, you’re kind of on your own… Dusk doesn’t provide a means to build objects outside of core. I recommend option 2 (below).

for data in map.layer["object layer"].objDatas() do -- 'data' will refer to each object's data stored in Dusk's core object data structure. -- Some things you might need to know about the structure: -- `data.type` = the type of object (viz. "rect", "ellipse", etc.) -- `data.transfer` = properties which will be set on the object when it's created. For example, this has `transfer.x` set to the object's final X position, `transfer.rotation` set to the rotation, etc. Anything you set in here will show up on the object when it's built. end

2. Use system time to sync object positions

This would be a good thing for future development, too, as it would allow you to implement better controls for objects’ timing. What I mean is to set some properties on your objects to denote “start cycle time”, “cycle length”, etc., then in your code sync the objects according to that. You can use Dusk’s addObjectListener function to specify objects with type = “spike” or something:

map.layer["object layer"].addObjectListener( "type", "spike", -- Listen for all objects with type = "spike" "drawn", -- Listen for when they're drawn function(event) local spike = event.object -- event.object is the object that was drawn -- Use this listener to sync the spike's position when it's created if spikeShouldBeUp(spike) then -- This function would take the spike's properties and tell whether, given the current time and the spike's properties, it should be up or down goUp(spike) -- STAB! (R.I.P Intrepid Adventurer.) else goDown(spike) -- Run for it! They're down! end -- Also, you probably won't need it, but event.name is the name of the event ("drawn" in this case) end )
  • Caleb

thanks for the help :slight_smile: