Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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;
    }

And the camera is send directly to the GPU with: c3d.setProgramConstantsFromMatrix(Context3DProgramType.VERTEX, 0, cameraMatrix, true);

And these are the shaders:

------Vertex Shader------
m44 op, va0, vc0
mov v0, va1.xy
mov v0.z, va0.z

------Fragment Shader------
tex ft0, v0, fs0 <2d,linear,nomip>
mov oc, ft1

Here is a example and here are two screenshots to show what I mean: Frame 1Frame 2

How do I only let the inside of the stage3D scroll and not the whole stage?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I already figured it out, the problem was in the fact that I had different passes for the shaders.

So my shader logic was like this:

  1. Draw Stage to Texture as normal and as diffuse map
  2. Draw the Texture to the Stage

And for both passes I used the same transformation Matrix3D, so when the Stage was panned the texture that the whole Stage was drawn on was also panned. The solution is that all I had to do was create a simple Matrix3D object for drawing the Textures to the Stage, because the positions of the Texture should never change.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.