diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua index c9fc6b1..a1f0ee1 100644 --- a/gamecore/modules/world/baseworld.lua +++ b/gamecore/modules/world/baseworld.lua @@ -29,6 +29,8 @@ local BaseWorld = Object:extend() local Sti = require(cwd .. "libs.sti") local CameraSystem = require(cwd .. "camera") +local PADDING_VALUE = 10/100 + -- INIT FUNCTIONS -- All functions to init the world and the map @@ -138,6 +140,17 @@ function BaseWorld:getActors() return self.actors end +function BaseWorld:getVisibleActors(id) + local camx, camy, camw, camh = self.cameras:getViewCoordinate(id) + local paddingw = camw * PADDING_VALUE + local paddingh = camh * PADDING_VALUE + local x = camx - paddingw + local y = camy - paddingh + local w = camw + paddingw * 2 + local h = camh + paddingh * 2 + return self:queryRect(x, y, w, h) +end + -- INFO FUNCTIONS -- Give infos about the world @@ -360,7 +373,12 @@ function BaseWorld:draw(dt) end function BaseWorld:drawActors(id) - local actors = self:getActors() + local actors + if (id == nil) then + actors = self:getActors() + else + actors = self:getVisibleActors(id) + end for i,v in ipairs(actors) do v:draw() end