Stage3D Camera problem
Posted
by
Thomas Versteeg
on Game Development
See other posts from Game Development
or by Thomas Versteeg
Published on 2012-11-21T15:35:58Z
Indexed on
2012/11/21
17:16 UTC
Read the original article
Hit count: 559
I am trying to create a 2D Stage3D game where you can move the camera around the level in an RTS style. I thought about using Orthographic Matrix3D functions for this but when I try to scroll the whole "stage" also scrolls.
This is the Camera code:
public function Camera2D(width:int, height:int, zoom:Number = 1) {
resize(width, height);
_zoom = zoom;
}
public function resize(width:Number, height:Number):void {
_width = width;
_height = height;
_projectionMatrix = makeMatrix(0, width, 0, height);
_recalculate = true;
}
protected function makeMatrix(left:Number, right:Number, top:Number, bottom:Number, zNear:Number = 0, zFar:Number = 1):Matrix3D {
return new Matrix3D(Vector.<Number>([
2 / (right - left), 0, 0, 0,
0, 2 / (top - bottom), 0, 0,
0, 0, 1 / (zFar - zNear), 0,
0, 0, zNear / (zNear - zFar), 1
]));
}
public function get viewMatrix():Matrix3D {
if (_recalculate) {
_recalculate = false;
_viewMatrix.identity();
_viewMatrix.appendTranslation( -_width / 2 - _x, -_height / 2 - y, 0);
_viewMatrix.appendScale(_zoom, _zoom, 1);
_renderMatrix.identity();
_renderMatrix.append(_viewMatrix);
_renderMatrix.append(_projectionMatrix);
}
return _renderMatrix;
}
Here are two screenshots to show what I mean:
How do I only let the inside of the stage3D scroll and not the whole stage?
© Game Development or respective owner