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

function remove(s, ...)^ top

function instance:remove(s, ...)^ top

Unbinds (removes) functions from signal s.

Parameters:
string s
The signal identifier.
functions ...
Functions to unbind from the signal.
Returns:
Nothing
Example:
Signal.remove('level-load', handle)

function clear(s)^ top

function instance:clear(s)^ top

Removes all functions from signal s.

Parameters:
string s
The signal identifier.
Returns:
Nothing
Example:
Signal.clear('key-left')

function emit_pattern(p, ...)^ top

function instance:emit_pattern(p, ...)^ top

Emits all signals matching a string pattern.

Parameters:
string p
The signal identifier pattern.
mixed ... (optional)
Arguments to pass to the bound functions.
Returns:
Nothing
Example:
Signal.emit_pattern('^update%-.*', dt)

function remove_pattern(p, ...)^ top

function instance:remove_pattern(p, ...)^ top

Removes functions from all signals matching a string pattern.

Parameters:
string p
The signal identifier pattern.
functions ...
Functions to unbind from the signals.
Returns:
Nothing
Example:
Signal.remove_pattern('key%-.*', play_click_sound)

function clear_pattern(p)^ top

function instance:clear_pattern(p)^ top

Removes all functions from all signals matching a string pattern.

Parameters:
string p
The signal identifier pattern.
Returns:
Nothing
Example:
Signal.clear_pattern('sound%-.*')
Signal.clear_pattern('.*') -- clear all signals

hump.camera^ top

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.

Module overview

new()
Create a new camera object.
camera:rotate()
Rotate camera object.
camera:move()
Move camera object.
camera:attach()
Attach camera object.
camera:detach()
Detach camera object.
camera:draw()
Attach, draw and detach.
camera:worldCoords()
Convert point to world coordinates.
camera:cameraCoords()
Convert point to camera coordinates.
camera:mousepos()
Get mouse position in world coordinates.

function new(x,y, zoom, rot)^ top

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().

Parameters:
numbers x,y
Point for the camera to look at.
number zoom
Camera zoom.
number rot
Camera rotation in radians.
Returns:
camera
A new camera object.
Example:
camera = require 'hump.camera'
+end

function remove(s, ...)^ top

function instance:remove(s, ...)^ top

Unbinds (removes) functions from signal s.

Parameters:
string s
The signal identifier.
functions ...
Functions to unbind from the signal.
Returns:
Nothing
Example:
Signal.remove('level-load', handle)

function clear(s)^ top

function instance:clear(s)^ top

Removes all functions from signal s.

Parameters:
string s
The signal identifier.
Returns:
Nothing
Example:
Signal.clear('key-left')

function emit_pattern(p, ...)^ top

function instance:emit_pattern(p, ...)^ top

Emits all signals matching a string pattern.

Parameters:
string p
The signal identifier pattern.
mixed ... (optional)
Arguments to pass to the bound functions.
Returns:
Nothing
Example:
Signal.emit_pattern('^update%-.*', dt)

function remove_pattern(p, ...)^ top

function instance:remove_pattern(p, ...)^ top

Removes functions from all signals matching a string pattern.

Parameters:
string p
The signal identifier pattern.
functions ...
Functions to unbind from the signals.
Returns:
Nothing
Example:
Signal.remove_pattern('key%-.*', play_click_sound)

function clear_pattern(p)^ top

function instance:clear_pattern(p)^ top

Removes all functions from all signals matching a string pattern.

Parameters:
string p
The signal identifier pattern.
Returns:
Nothing
Example:
Signal.clear_pattern('sound%-.*')
Signal.clear_pattern('.*') -- clear all signals

hump.camera^ top

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.

Module overview

new()
Create a new camera object.
camera:rotate()
Rotate camera object.
camera:rotation()
Get camera rotation.
camera:move()
Move camera object.
camera:pos()
Get camera position..
camera:attach()
Attach camera object.
camera:detach()
Detach camera object.
camera:draw()
Attach, draw and detach.
camera:worldCoords()
Convert point to world coordinates.
camera:cameraCoords()
Convert point to camera coordinates.
camera:mousepos()
Get mouse position in world coordinates.

function new(x,y, zoom, rot)^ top

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().

Parameters:
numbers x,y
Point for the camera to look at.
number zoom
Camera zoom.
number rot
Camera rotation in radians.
Returns:
camera
A new camera object.
Example:
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

function camera:move(dx,dy)^ top

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.

Parameters:
numbers dx,dy
Direction to move the camera.
Returns:
camera
The camera object.
Example:
function love.update(dt)
+end

function camera:rotation()^ top

Returns camera.rot.

Parameters:
None
Returns:
number
Rotation angle in radians.
Example:
love.graphics.print(camera:rotation(), 10, 10)

function camera:move(dx,dy)^ top

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.

Parameters:
numbers dx,dy
Direction to move the camera.
Returns:
camera
The camera object.
Example:
function love.update(dt)
+    camera:move(dt * 5, dt * 6)
+end
function love.update(dt)
     camera:move(dt * 5, dt * 6):rotate(dt)
+end

function camera:pos()^ top

Returns camera.x, camera.y.

Parameters:
None
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 camera:attach()^ top

Start looking through the camera.

Apply camera transformations, i.e. move, scale and rotate everything until camera:detach() as if looking through the camera.

Parameters:
None
Returns:
Nothing
Example:
function love.draw()
     camera:attach()
     draw_world()