diff --git a/doc.lua b/doc.lua index d03616b..bd2f07e 100644 --- a/doc.lua +++ b/doc.lua @@ -1367,8 +1367,6 @@ Module { name = "hump.camera", title = "Camera", short = "A camera for LÖVE", long = [===[ - {!Depends on hump.vector-light} - A camera utility for LÖVE. A camera can "look" at a position. It can zoom in and out and it can rotate it's view. In the background, this is done by actually moving, scaling and rotating everything in the game world. But don't worry about @@ -1423,6 +1421,19 @@ cam = camera(100,100, 2, math.pi/2) }, }, + Function { name = "camera:rotation", + short = "Get camera rotation.", + long = [===[Returns {#camera.rot}.]===], + + params = {}, + + returns = { + {"number", "Rotation angle in radians."} + }, + + example = [===[love.graphics.print(camera:rotation(), 10, 10)]===], + }, + Function { name = "camera:move", short = "Move camera object.", long = [===[ @@ -1439,10 +1450,33 @@ cam = camera(100,100, 2, math.pi/2) }, example = { + "function love.update(dt)\n camera:move(dt * 5, dt * 6)\nend", "function love.update(dt)\n camera:move(dt * 5, dt * 6):rotate(dt)\nend" }, }, + Function { name = "camera:pos", + short = "Get camera position..", + long = [===[Returns {#camera.x, camera.y}.]===], + + params = {}, + + returns = { + {"numbers", "Camera position."}, + }, + + example = [===[-- let the camera fly! +local cam_dx, cam_dy = 0, 0 +function love.mousereleased(x,y) + local cx,cy = camera:position() + dx, dy = x-cx, y-cy +end + +function love.update(dt) + camera:move(dx * dt, dy * dt) +end]===], + }, + Function { name = "camera:attach", short = "Attach camera object.", long = [===[ diff --git a/index.html b/index.html index 0f40bea..8a1425b 100644 --- a/index.html +++ b/index.html @@ -316,7 +316,7 @@ end
if level.is_finished() then
end
function on_collide(dt, a,b, dx,dy)
a.signals:emit('collide', b, dx, dy)
b.signals:emit('collide', a, -dx,-dy)
-end
Unbinds (removes) functions from signal s
.
s
...
Signal.remove('level-load', handle)
Removes all functions from signal s
.
s
Signal.clear('key-left')
Emits all signals matching a string pattern.
p
...
(optional)Signal.emit_pattern('^update%-.*', dt)
Removes functions from all signals matching a string pattern.
p
...
Signal.remove_pattern('key%-.*', play_click_sound)
Removes all functions from all signals matching a string pattern.
p
Signal.clear_pattern('sound%-.*')
Signal.clear_pattern('.*') -- clear all signals
Camera = require "hump.camera"
Depends on hump.vector-light
A camera utility for LÖVE. A camera can "look" at a position. It can zoom in and out and it can rotate it's view. In the background, this is done by actually moving, scaling and rotating everything in the game world. But don't worry about that.
Creates a new camera object. You can access the camera position using camera.x, camera.y
, the zoom using camera.zoom
and the rotation using camera.rot
.
The module variable name can be used at a shortcut to new()
.
x,y
zoom
rot
camera = require 'hump.camera'
+end
Unbinds (removes) functions from signal s
.
s
...
Signal.remove('level-load', handle)
Removes all functions from signal s
.
s
Signal.clear('key-left')
Emits all signals matching a string pattern.
p
...
(optional)Signal.emit_pattern('^update%-.*', dt)
Removes functions from all signals matching a string pattern.
p
...
Signal.remove_pattern('key%-.*', play_click_sound)
Removes all functions from all signals matching a string pattern.
p
Signal.clear_pattern('sound%-.*')
Signal.clear_pattern('.*') -- clear all signals
Camera = require "hump.camera"
A camera utility for LÖVE. A camera can "look" at a position. It can zoom in and out and it can rotate it's view. In the background, this is done by actually moving, scaling and rotating everything in the game world. But don't worry about that.
Creates a new camera object. You can access the camera position using camera.x, camera.y
, the zoom using camera.zoom
and the rotation using camera.rot
.
The module variable name can be used at a shortcut to new()
.
x,y
zoom
rot
camera = require 'hump.camera'
-- camera looking at (100,100) with zoom 2 and rotated by 45 degrees
cam = camera(100,100, 2, math.pi/2)
@@ -324,8 +324,19 @@ cam = camera(100,100, 2, math.pi/2)
camera:rotate(dt)
end
function love.update(dt)
camera:rotate(dt):move(dt,dt)
-end
Move the camera by some vector. To set the position, use camera.x,camera.y = new_x,new_y
.
This function is shortcut to camera.x,camera.y = camera.x+dx, camera.y+dy
.
dx,dy
function love.update(dt)
+end
Returns camera.rot
.
love.graphics.print(camera:rotation(), 10, 10)
Move the camera by some vector. To set the position, use camera.x,camera.y = new_x,new_y
.
This function is shortcut to camera.x,camera.y = camera.x+dx, camera.y+dy
.
dx,dy
function love.update(dt)
+ camera:move(dt * 5, dt * 6)
+end
function love.update(dt)
camera:move(dt * 5, dt * 6):rotate(dt)
+end
Returns camera.x, camera.y
.
-- let the camera fly!
+local cam_dx, cam_dy = 0, 0
+function love.mousereleased(x,y)
+ local cx,cy = camera:position()
+ dx, dy = x-cx, y-cy
+end
+
+function love.update(dt)
+ camera:move(dx * dt, dy * dt)
end
Start looking through the camera.
Apply camera transformations, i.e. move, scale and rotate everything until camera:detach()
as if looking through the camera.
function love.draw()
camera:attach()
draw_world()