Strange nil value for object position

There must be a good explanation for this that I failed to realize:

I am trying to move my character around the map, with following setup:

local map = dusk.buildMap('maps/large.json') local player = map.layer['Main'].object['Player'] map.setCameraFocus(player)

my event handler is simple, check for key event and increment/decrement player.x / player.y

this works, until player.x or player.y exceeds the device screen size.

say for iphone 6, where screen width is 375, when player.x move beyond 375, it returns nil instead:

attempt to perform arithmetic on field 'x' (a nil value)

Why? What does player.x means in this context? I thought it was “object player’s position relative to the map”…

PS: I wish there is an extensive API doc for dusk engine…

This is actually working as expected. Dusk automatically culls objects when they move outside the screen. This means that if you move the camera to where an object at its original position is outside the screen, it’ll remove it. This saves a bunch of memory and greatly improves Dusk’s speed.

For the player object and other persistent objects, you should create them manually and add them to the map rather than create them in Tiled. This will keep Dusk from culling the object, and has the added bonus of improved flexibility and control over the object. If you simply must use a Tiled object instead of a manual object, turn object culling off before building your map:

dusk.setPreference("enableObjectCulling", false)

Also, I’m currently working on a refactor of Dusk for 1.0. I know the lack of API docs frustrates a lot of people, so I can assure you that they’ll come with 1.0.

  • Caleb

Thx, this makes a lot of sense now.

This is actually working as expected. Dusk automatically culls objects when they move outside the screen. This means that if you move the camera to where an object at its original position is outside the screen, it’ll remove it. This saves a bunch of memory and greatly improves Dusk’s speed.

For the player object and other persistent objects, you should create them manually and add them to the map rather than create them in Tiled. This will keep Dusk from culling the object, and has the added bonus of improved flexibility and control over the object. If you simply must use a Tiled object instead of a manual object, turn object culling off before building your map:

dusk.setPreference("enableObjectCulling", false)

Also, I’m currently working on a refactor of Dusk for 1.0. I know the lack of API docs frustrates a lot of people, so I can assure you that they’ll come with 1.0.

  • Caleb

Thx, this makes a lot of sense now.