love.scene = require("scene")
local view = love.scene.newView() -- object-oriented style local s1 = view:newSprite(0, 0) -- Love2D style local s2 = love.scene.newSprite(0, 0) s2:setParent(view)Images, text and other types of drawable graphics are rendered as follows:
-- image local image = love.graphics.newImage("texture1.png") s1:setGraphic(image) -- text local font = love.graphics.getFont() local text = love.graphics.newText(font, "Hello world") s2:setGraphic(text)
function love.draw() view:draw() end
local sprite = view:newSprite(0, 0) -- draw local image = love.graphics.newImage("myimage.png") sprite:setGraphic(image) -- transform sprite:setPosition(100, 0) sprite:setRotation(math.pi/2) sprite:setScale(1, 2) -- modulate sprite:setColor(1, 0, 0) sprite:setAlpha(0.5) sprite:setMode("add")
local root = view:newLayer(0, 0) local a = root:newSprite(0, 0) local b = root:newSprite(0, 0) a:setGraphic(love.graphics.newImage('background.png')) b:setGraphic(love.graphics.newImage('foreground.png')) -- modify drawing order b:setDepth(1)
local view = love.scene.newView() -- shading local shader = love.graphics.newShader([[ vec4 effect( vec4 c, Image t, vec2 tc, vec2 sc ){ vec4 p = Texel(t, tc ); number a = (p.r+p.b+p.g)/3.0; number f = tc.x; p.r = p.r + (a - p.r)*f; p.g = p.g + (a - p.g)*f; p.b = p.b + (a - p.b)*f; return p; } ]]) view:setShader(shader)
function love.draw() view:draw() end
local view = love.scene.newView() local root = love.scene.newLayer(0, 0) local cam = root:newCamera(100, 0) cam:setRange(800, 400) view:setCamera(cam)
scene.copy(src, dest) |
scene.destroy(t) |
scene.new(t, ...) |
scene.newCamera(x, y) |
scene.newLayer(x, y) |
scene.newSprite(x, y) |
scene.newView(x, y, width, height) |
Arguments | |
---|---|
node | src Source node |
node | dest Destination node |
Arguments | |
---|---|
node | t Existing node |
Arguments | |
---|---|
node | t Existing node |
arguments | ... Constructor arguments |
Returns | |
node | New node object |
Arguments | |
---|---|
number | x X coordinate |
number | y Y coordinatex |
Returns | |
camera | New camera object |
Arguments | |
---|---|
number | x X coordinate |
number | y Y coordinate |
Returns | |
layer | New layer object |
Arguments | |
---|---|
number | x X coordinate |
number | y Y coordinate |
Returns | |
sprite | New sprite object |
Arguments | |
---|---|
number | x (optional) X-position in pixels |
number | y (optional) Y-position in pixels |
number | width (optional) Width in pixels |
number | height (optional) Height in pixels |
Returns | |
view | New view object |
node.construct(x, y) |
node:compareDepth(other) |
node:deconstruct() |
node:destroy() |
node:getDepth() |
node:getParent() |
node:getPosition() |
node:getRoot() |
node:getRotation() |
node:getScale() |
node:getTransform() |
node:getVisible() |
node:localToParent(x, y) |
node:localToRoot(x, y) |
node:localToWindow(x, y) |
node:parentToLocal(x, y) |
node:reset(x, y) |
node:rootToLocal(x, y) |
node:setDepth(index) |
node:setParent(parent) |
node:setPosition(x, y) |
node:setRotation(angle) |
node:setScale(sx, sy) |
node:setTransform(x, y, angle) |
node:setVisible(True) |
node:type() |
node:windowToLocal(x, y) |
Arguments | |
---|---|
number | x X-coordinate |
number | y Y-coordinate |
Returns | |
node | New node |
Arguments | |
---|---|
node | other Other other |
Returns | |
boolean | True if this node is in front of the other |
Returns | |
---|---|
number | Depth index |
Returns | |
---|---|
layer | Current parent layer |
Returns | |
---|---|
number | X-coordinate |
number | Y-coordinate |
Returns | |
---|---|
layer | Root layer |
Returns | |
---|---|
number | Angle in radians |
Returns | |
---|---|
number | X-axis scale |
number | Y-axis scale |
Returns | |
---|---|
number | X-coordinate |
number | Y-coordinate |
number | Angle in radians |
Returns | |
---|---|
boolean | True if visible |
Arguments | |
---|---|
number | x Local X-coordinate |
number | y Local Y-coordinate |
Returns | |
number | Parent X-coordinate |
number | Parent Y-coordinate |
Arguments | |
---|---|
number | x Local X-coordinate |
number | y Local Y-coordinate |
Returns | |
number | Scene X-coordinate |
number | Scene Y-coordinate |
Arguments | |
---|---|
number | x Local X-coordinate |
number | y Local Y-coordinate |
Returns | |
number | Window X-coordinate |
number | Window Y-coordinate |
Arguments | |
---|---|
number | x Parent X-coordinate |
number | y Parent Y-coordinate |
Returns | |
number | Local X-coordinate |
number | Local Y-coordinate |
Arguments | |
---|---|
number | x X-coordinate |
number | y Y-coordinate |
Arguments | |
---|---|
number | x Scene X-coordinate |
number | y Scene Y-coordinate |
Returns | |
number | Local X-coordinate |
number | Local Y-coordinate |
Arguments | |
---|---|
number | index Depth index (could be negative) |
Arguments | |
---|---|
layer | parent New parent layer |
Arguments | |
---|---|
number | x X-coordinate |
number | y Y-coordinate |
Arguments | |
---|---|
number | angle Angle in radians |
Arguments | |
---|---|
number | sx X-axis scale |
number | sy Y-axis scale |
Arguments | |
---|---|
number | x X-coordinate |
number | y Y-coordinate |
number | angle Angle in radians |
Arguments | |
---|---|
boolean | True if visible |
Returns | |
---|---|
string | Node type ("Sprite", "Layer" or "View"). |
Arguments | |
---|---|
number | x Window X-coordinate |
number | y Window Y-coordinate |
Returns | |
number | Local X-coordinate |
number | Local Y-coordinate |
Functions inherited from "node" | |
---|---|
node:compareDepth(other) | |
node:destroy() | |
node:getDepth() | |
node:getParent() | |
node:getPosition() | |
node:getRoot() | |
node:getRotation() | |
node:getScale() | |
node:getTransform() | |
node:getVisible() | |
node:localToParent(x, y) | |
node:localToRoot(x, y) | |
node:localToWindow(x, y) | |
node:parentToLocal(x, y) | |
node:rootToLocal(x, y) | |
node:setDepth(index) | |
node:setParent(parent) | |
node:setPosition(x, y) | |
node:setRotation(angle) | |
node:setScale(sx, sy) | |
node:setTransform(x, y, angle) | |
node:setVisible(True) | |
node:type() | |
node:windowToLocal(x, y) | |
Functions | |
sprite.construct(x, y) | |
sprite:deconstruct() | |
sprite:draw() | |
sprite:getAlpha() | |
sprite:getColor() | |
sprite:getGraphic() | |
sprite:getMode() | |
sprite:getShader() | |
sprite:reset(x, y) | |
sprite:setAlpha(alpha) | |
sprite:setColor(red, green, blue) | |
sprite:setGraphic(drawable, quad, x, y, angle, sx, sy, ox, oy, kx, ky) | |
sprite:setMode(mode) | |
sprite:setShader(shader) |
Arguments | |
---|---|
number | x X coordinate |
number | y Y coordinate |
Returns | |
sprite | New sprite |
Returns | |
---|---|
number | Alpha value (0-1) |
Returns | |
---|---|
number | Red value (0-1) |
number | Green value (0-1) |
number | Blue value (0-1) |
Returns | |
---|---|
userdata | Drawable graphic |
userdata | Quad or nil |
Returns | |
---|---|
string | mode Blend mode |
Returns | |
---|---|
userdata | Shader object |
Arguments | |
---|---|
number | x X-coordinate |
number | y Y-coordinate |
Arguments | |
---|---|
number | alpha Alpha value (0-1) |
Arguments | |
---|---|
number | red Red value (0-1) |
number | green Green value (0-1) |
number | blue Blue value (0-1) |
Arguments | |
---|---|
userdata | drawable Drawable graphic |
userdata | quad (optional) Optional quad |
number | x (0) X coordinate |
number | y (0) y coordinate |
number | angle (0) Angle |
number | sx (1) X axis scale |
number | sy (1) Y axis scale |
number | ox (0) X axis offset |
number | oy (0) Y axis offset |
number | kx (0) X axis shearing |
number | ky (0) Y axis shearing |
Arguments | |
---|---|
string | mode Blend mode: "alpha", "add", "subtract" or "multiply" |
Arguments | |
---|---|
userdata | shader Shader object |
Functions inherited from "node" | |
---|---|
node:compareDepth(other) | |
node:destroy() | |
node:getDepth() | |
node:getParent() | |
node:getPosition() | |
node:getRoot() | |
node:getRotation() | |
node:getScale() | |
node:getTransform() | |
node:getVisible() | |
node:localToParent(x, y) | |
node:localToRoot(x, y) | |
node:localToWindow(x, y) | |
node:parentToLocal(x, y) | |
node:rootToLocal(x, y) | |
node:setDepth(index) | |
node:setParent(parent) | |
node:setPosition(x, y) | |
node:setRotation(angle) | |
node:setScale(sx, sy) | |
node:setTransform(x, y, angle) | |
node:setVisible(True) | |
node:type() | |
node:windowToLocal(x, y) | |
Functions | |
layer.construct(x, y) | |
layer:deconstruct() | |
layer:destroyChildren() | |
layer:draw() | |
layer:getChild(index) | |
layer:getChildDepth(child) | |
layer:insertChild(child) | |
layer:newCamera(x, y) | |
layer:newLayer(x, y) | |
layer:newSprite(x, y) | |
layer:removeChild(child) | |
layer:removeChildren() | |
layer:reset(x, y) | |
layer:setChildDepth(child, index) | |
layer:sort(func) |
Arguments | |
---|---|
number | x X coordinate |
number | y Y coordinate |
Returns | |
layer | New layer |
Arguments | |
---|---|
number | index Depth index |
Arguments | |
---|---|
node | child Child node |
Returns | |
number | Depth index |
Arguments | |
---|---|
node | child Child node |
Arguments | |
---|---|
number | x X-coordinate |
number | y Y-coordinate |
Returns | |
camera | New camera object |
Arguments | |
---|---|
number | x X-coordinate |
number | y Y-coordinate |
Returns | |
layer | New layer object |
Arguments | |
---|---|
number | x X-coordinate |
number | y Y-coordinate |
Returns | |
sprite | New sprite object |
Arguments | |
---|---|
node | child Child node |
Arguments | |
---|---|
number | x X-coordinate |
number | y Y-coordinate |
Arguments | |
---|---|
node | child Child node |
number | index Depth index (could be negative) |
Arguments | |
---|---|
function | func (optional) Comparison function |
Functions inherited from "node" | |
---|---|
node:compareDepth(other) | |
node:deconstruct() | |
node:destroy() | |
node:getDepth() | |
node:getParent() | |
node:getPosition() | |
node:getRoot() | |
node:getRotation() | |
node:getScale() | |
node:getTransform() | |
node:getVisible() | |
node:localToParent(x, y) | |
node:localToRoot(x, y) | |
node:localToWindow(x, y) | |
node:parentToLocal(x, y) | |
node:rootToLocal(x, y) | |
node:setDepth(index) | |
node:setParent(parent) | |
node:setPosition(x, y) | |
node:setRotation(angle) | |
node:setScale(sx, sy) | |
node:setTransform(x, y, angle) | |
node:setVisible(True) | |
node:type() | |
node:windowToLocal(x, y) | |
Functions | |
camera.construct(x, y) | |
camera:draw() | |
camera:getRange() | |
camera:render(view) | |
camera:reset(x, y) | |
camera:setRange(width, height) |
Arguments | |
---|---|
number | x X coordinate |
number | y Y coordinate |
Returns | |
camera | New camera |
Returns | |
---|---|
number | Range width in scene units |
number | Range height in scene units |
Arguments | |
---|---|
node | view View object |
Arguments | |
---|---|
number | x X-coordinate |
number | y Y-coordinate |
Arguments | |
---|---|
number | width Range width in scene units |
number | height Range height in scene units |
Arguments | |
---|---|
number | x (optional) X-position in pixels |
number | y (optional) Y-position in pixels |
number | width (optional) Width in pixels |
number | height (optional) Height in pixels |
Returns | |
view | New view object |
Returns | |
---|---|
number | Red value (0-1) |
number | Green value (0-1) |
number | Blue value (0-1) |
number | Alpha value (0-1) |
Returns | |
---|---|
camera | camera Camera object |
Returns | |
---|---|
number | Width in pixels |
number | Height in pixels |
Returns | |
---|---|
number | X-ratio from 0 to 1 |
number | Y-ratio from 0 to 1 |
Returns | |
---|---|
number | X-position in pixels |
number | Y-position in pixels |
Returns | |
---|---|
userdata | Pixel shader object |
Arguments | |
---|---|
number | x Local X-coordinate |
number | y Local Y-coordinate |
Returns | |
number | Scene X-coordinate |
number | Scene Y-coordinate |
Arguments | |
---|---|
number | x X scene coordinate |
number | y Y scene coordinate |
Returns | |
number | X-position in pixels |
number | Y-position in pixels |
Arguments | |
---|---|
number | x X-position in pixels |
number | y Y-position in pixels |
number | width Width in pixels |
number | height Height in pixels |
Arguments | |
---|---|
number | x Scene X-coordinate |
number | y Scene Y-coordinate |
Returns | |
number | Local X-coordinate |
number | Local Y-coordinate |
Arguments | |
---|---|
number | x X scene coordinate |
number | y Y scene coordinate |
Returns | |
number | X-position in pixels |
number | Y-position in pixels |
Arguments | |
---|---|
number | red Red value (0-1) |
number | green Green value (0-1) |
number | blue Blue value (0-1) |
number | alpha (optional) Alpha value (0-1) |
Arguments | |
---|---|
camera | camera Camera object |
Arguments | |
---|---|
number | width Width in pixels |
number | height Height in pixels |
Arguments | |
---|---|
number | ox X-ratio from 0 to 1 |
number | oy Y-ratio from 0 to 1 |
Arguments | |
---|---|
number | x X-position in pixels |
number | y Y-position in pixels |
Arguments | |
---|---|
userdata | shader (optional) Pixel shader object |
Arguments | |
---|---|
number | x X-position in pixels |
number | y Y-position in pixels |
Returns | |
number | X scene coordinate |
number | Y scene coordinate |
Arguments | |
---|---|
number | x X-position in pixels |
number | y Y-position in pixels |
Returns | |
number | X scene coordinate |
number | Y scene coordinate |