If I read you correctly, your problem is with enemies moving into the lower edge of the map. Is that correct?
If so, you can create a snapshot or container which stretches to the map’s lower edge, insert your map into it, and use that to clip off your enemies as required.
Just my two cents. I would not use a snapshot for this since it would require a lot of re-drawing (by the canvas) every frame. I would use a Container since that can extend beyond the screen and handles clipping seamlessly.
Caleb, correct me if I am wrong, isn’t it possible to tell Dusk to extend the bounds of the map culling region to be outside of the screen? Wouldn’t doing that solve bitinn’s problem?
@jerejigga actually my problem is not about enemy spawning outside of screen (they will be created and inserted onto the map, I am pretty sure that will not be culled, right?)
my problem is trying to insert an enemy on screen, but off the map (see my screenshot, say I insert an enemy below the map in the black screen region), I only want it to be visible when enemy move onto the map.
Well, in that case, one approach would be to just put a black rectangle at the bottom of the map and, using layers, insert the monster between the map and the black rectangle.
This is what I was referring to with the container or snapshot:
local map = dusk.buildMap("map.json") local container = display.newContainer(map.data.mapWidth, map.data.mapHeight) container:insert(map) -- Now the map is in a container and edges will be clipped. -- Play with the container's and map's X/Y positions to get the correct clipping position.
If I read you correctly, your problem is with enemies moving into the lower edge of the map. Is that correct?
If so, you can create a snapshot or container which stretches to the map’s lower edge, insert your map into it, and use that to clip off your enemies as required.
Just my two cents. I would not use a snapshot for this since it would require a lot of re-drawing (by the canvas) every frame. I would use a Container since that can extend beyond the screen and handles clipping seamlessly.
Caleb, correct me if I am wrong, isn’t it possible to tell Dusk to extend the bounds of the map culling region to be outside of the screen? Wouldn’t doing that solve bitinn’s problem?
@jerejigga actually my problem is not about enemy spawning outside of screen (they will be created and inserted onto the map, I am pretty sure that will not be culled, right?)
my problem is trying to insert an enemy on screen, but off the map (see my screenshot, say I insert an enemy below the map in the black screen region), I only want it to be visible when enemy move onto the map.
Well, in that case, one approach would be to just put a black rectangle at the bottom of the map and, using layers, insert the monster between the map and the black rectangle.
This is what I was referring to with the container or snapshot:
local map = dusk.buildMap("map.json") local container = display.newContainer(map.data.mapWidth, map.data.mapHeight) container:insert(map) -- Now the map is in a container and edges will be clipped. -- Play with the container's and map's X/Y positions to get the correct clipping position.