http://ebens.me/2011/04/19/cameras-in-l ... he-basics/

Today I wanted to program again with Löve, but the old camera system doesn't seem to work anymore.

I keep getting the error "Attempt to index local "self" (a number value)".

The Error itself appears in the function camera:setPosition when trying to set x and y.

What is wrong with the code associated with the camera?

I already tried to index the table "camera" directly instead of .self, call it from different functions and so on.

Camera Object

Code: Select all

```
camera = {}
camera.x = 0
camera.y = 0
camera.scaleX = 1
camera.scaleY = 1
camera.rotation = 0
```

Code: Select all

```
function camera:set()
love.graphics.push()
love.graphics.rotate(-self.rotation)
love.graphics.scale(1 / self.scaleX, 1 / self.scaleY)
love.graphics.translate(-self.x, -self.y)
end
function camera:unset()
love.graphics.pop()
end
function camera:move(dx, dy)
self.x = self.x + (dx or 0)
self.y = self.y + (dy or 0)
end
function camera:rotate(dr)
self.rotation = self.rotation + dr
end
function camera:scale(sx, sy)
sx = sx or 1
self.scaleX = self.scaleX * sx
self.scaleY = self.scaleY * (sy or sx)
end
function camera:setPosition(x, y)
--self.x = rOriginX+(player.x-player.y)*16-windowX/4+16 USE THIS TO FOCUS ON A OBJECT/ENTITY
--self.y = rOriginY+((player.y+player.x)*16)/2-windowY/4+24
self.x = x
self.y = y
end
function camera:setScale(sx, sy)
self.scaleX = sx or self.scaleX
self.scaleY = sy or self.scaleY
end
```

Code: Select all

```
if keyMap["up"] then
camera.setPosition(camera.x, camera.y-100*dt)
elseif keyMap["down"] then
camera.setPosition(camera.x, camera.y+100*dt)
elseif keyMap["left"] then
camera.setPosition(camera.x-100*dt, camera.y)
elseif keyMap["right"] then
camera.setPosition(camera.x+100*dt, camera.y)
end
```