Hello ulydev5,
Sprites are constrained to the map by default. You can set map constraints for each edge of the map individually by setting a sprite’s constrainToMap property, which takes a table of booleans.
--sprite.constrainToMap = {left, top, right, bottom} sprite.constrainToMap = {false, false, false, false}
You can also set this in a sprite’s setup table before calling addSprite. The table parameter is formatted the same way as the sprite’s property and has the effect of setting the sprite’s property just as above.
Checking whether an object is in the maps bounds is a matter of retrieving the size of the map and checking whether the sprite’s .x and .y properties are greater than 0 and less than the map size. If any one value is outside of this area, the map is outside of the map bounds. You may want to add the sprite’s width and height to these checks to determine when the entire sprite has left the map rather than just its origin.
local map = mte.getMap() local mapWidth = map.width \* map.tilewidth local mapHeight = map.height \* map.tileheight local gameLoop = function(event) if sprite.x \< 0 or sprite.x \> mapWidth or sprite.y \< 0 or sprite.y \> mapHeight then print("The sprite has left the map") end ... mte.update() end Runtime:addEventListener("enterFrame", gameLoop)