Camera = Entity:createSubClass();

function Camera:init()

   self:setForceUpdate(true);
   self:setEditorVisibleOnly(true);

   --self:setLayer(3);

end

function Camera:update()

   local target = self:getLinkTarget();
   local ent = entitiesByName[target];

   local x, y = ent:getPos(); 

   local sx, sy = getScreenSize();

   local currentTop = y + (sy / 2);
   local currentLeft = x - (sx / 2);

   local currentRight = x + (sx / 2);
   local currentBottom = y - (sy / 2);

   if currentTop > levelActiveArea[2] then
      y = levelActiveArea[2] - (sy/2);
   elseif currentBottom < -1 * levelActiveArea[2] then
      y = -1 * levelActiveArea[2] + (sy/2);
   end

   if currentLeft < -1 * levelActiveArea[1] then
      x = -1 * levelActiveArea[1] + (sx/2);
   elseif currentRight > levelActiveArea[1] then
      x = levelActiveArea[1] - (sx/2);
   end

   setCameraPos(x, y);
   -- self:setPos(x, 0);

end

function Camera:destruct()

   writeConsole("Camera wants to die!\n");

end

