A simple 2D camera for Gideros.
- 2 shape types
- rectangle
- circle
- Dead zone
- Soft zone
- Shaking
- Bounds
- Smooth object follow
- Zooming
- Rotating
Create camera:
camera = GCam.new(yourScene [, anchorX, anchorY]) -- anchor by default is (0.5, 0.5)
stage:addChild(camera)
Following:
camera:setFollow(myObject)
stage:addEventListener("enterFrame", function(e)
local dt = e.deltaTime
camera:update(dt)
end)
-- remove following:
camera:setFollow(nil)
Change position:
camera:goto(x, y)
Sets camera size to window size
camera:setAutoSize(flag)
Shaking:
-- duration (number): time is s.
-- distance (number): maximum shake offset
camera:shake(duraion [, distance])
Zooming:
camera:zoom(step)
-- for example
camera:zoom(0.1) -- zoom in by 0.1
camera:zoom(-0.1) -- zoom out by 0.1
camera:setZoom(2) -- set zoom directly
Shape:
-- shapeType(string): function name
-- can be "rectangle" or "circle"
-- you can create custom shape by
-- adding a new method to a class
-- then use its name as shapeType
camera:setShape(shapeType)
Dead zone: Camera does not move in this zone
camera:setDeadSize(w, h) -- dead zone size
camera:setDeadRadius(r) -- dead zone radius (only for "circle" shape)
Soft zone: Camera intepolate its position towards target
camera:setSoftSize(w, h) -- soft zone size
camera:setSoftRadius(r) -- soft zone radius (only for "circle" shape)
Bounds:
camera:setBounds([left, top, right, bottom]) -- default value is 0 for each
-- or
camera:setLeftBound(left)
camera:seTopBound(top)
camera:setRightBound(right)
camera:setBottomBound(bottom)
Movement smoothing:
camera:setSmooth(x, y)
Debug graphics:
camera:setDebug(flag)
-- or
camera:switchDebug() -- turn on/off
Prediction:
camera:setPredictMode(mode) -- mode: true/false
camera:setPrediction(num) -- number betwwen 0 and 1
camera:lockPredictionX() -- no prediction on X axis
camera:lockPredictionY() -- no prediction on X axis
camera:setLockPredictionX(flag) -- disable/enable prediction on X axis
camera:setLockPredictionY(flag) -- disable/enable prediction on X axis
camera:setPredictionSmoothing(num) -- smooth prediction