Spawn and move an enemy into the map

I am trying to spawn an enemy just outside the map, and gradually move it onto the map, like you see on every side-scrolling shooters.

The problem: given my map layout, how can I spawn an enemy just below the map, and show it when the enemy move into my map’s viewport.

Requirement: enemy movement is continuous, not discrete, so we need to handle partially visible enemy.

dE37SWI.png

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.

  • Caleb

Oh that’s what you meant by snapshot, I will have a go with it

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.

hope my explanation is clear :slight_smile:

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.

definitely, it was my solution as well, just didn’t feel too great about doing that.

ref: https://github.com/GymbylCoding/Dusk-Engine/issues/43

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.
  • Caleb

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.

  • Caleb

Oh that’s what you meant by snapshot, I will have a go with it

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.

hope my explanation is clear :slight_smile:

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.

definitely, it was my solution as well, just didn’t feel too great about doing that.

ref: https://github.com/GymbylCoding/Dusk-Engine/issues/43

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.
  • Caleb