Ejemplo n.º 1
0
        /**
         * Set the position, scale and rotation targets for the camera and begin animation.
         * @param xPos X Pan target value
         * @param yPos Y Pan target value
         * @param zoom Scale target value
         * @param rot Rotation rarget value
         * @param force Boolean to force the values to be set without easing or animation
         */
        public void moveTo(float xPos, float yPos, float zoom = 1f, float rot = 0f, bool force = false)
        {
            if (force || _easingPan != NO_MOTION)
            {
                _targetX = -CameraUtils.clamp(xPos, _boundingRect.left, _boundingRect.right);
                _targetY = -CameraUtils.clamp(yPos, _boundingRect.top, _boundingRect.bottom);
            }
            if (force || _easingZoom != NO_MOTION)
            {
                _targetZoom = CameraUtils.clamp(zoom, 0, float.PositiveInfinity);
            }
            if (force || _easingRotate != NO_MOTION)
            {
                _targetRot = rot;
            }

            if (force)
            {
                _world.x        = _targetX;
                _world.y        = _targetY;
                _harness.scaleX = _harness.scaleY = _targetZoom;
                _harness.setRotation(_targetRot);
            }
            else
            {
                startMoving();
            }
        }
Ejemplo n.º 2
0
        public Rectangle intersection(Rectangle toIntersect)
        {
            float l = CameraUtils.clamp(toIntersect.left, rect.left, rect.right);
            float r = CameraUtils.clamp(toIntersect.right, rect.left, rect.right);
            float t = CameraUtils.clamp(toIntersect.top, rect.top, rect.bottom);
            float b = CameraUtils.clamp(toIntersect.bottom, rect.top, rect.bottom);

            if (t >= b || l >= r)             // don't bother rendering if the texture is off screen
            {
                //return new InfiniteRectangle();
                return(new Rectangle(0, 0, 0, 0));
            }
            else
            {
                //return new InfiniteRectangle(l, t, r - l, b - t);
                return(asRectangle(new InfiniteRectangle(l, t, r - l, b - t)));
            }
        }
Ejemplo n.º 3
0
        /**
         * To be used as a handler for onEnterFrame.  Moves the camera towards its targets
         * @param e EnterFrameEvent
         */
        private void stepAnimation(CEvent e)
        {
            //clamp, ease, angleModulus and nearEquals are from com.byxb.utils.
            _world.x        = CameraUtils.clamp(CameraUtils.ease(_world.x, _targetX, _easingPan), _boundingRect.left, _boundingRect.right);
            _world.y        = CameraUtils.clamp(CameraUtils.ease(_world.y, _targetY, _easingPan), _boundingRect.top, _boundingRect.bottom);
            _harness.scaleX = _harness.scaleY = CameraUtils.ease(_harness.scaleX, _targetZoom, _easingZoom);
            _targetRot      = CameraUtils.angleModulus(_targetRot, _harness.getRotation());
            _harness.setRotation(CameraUtils.ease(_harness.getRotation(), _targetRot, _easingRotate));
            //_juggler.advanceTime(e.passedTime);
            _harness.updateRotation();

            //if pretty close to all the targets, treat as having reached the targets
            if (!_shaking && CameraUtils.nearEquals(_world.x, _targetX) && CameraUtils.nearEquals(_world.y, _targetY) && CameraUtils.nearEquals(_harness.scaleX, _targetZoom) && CameraUtils.nearEquals(_harness.getRotation(), _targetRot))
            {
                stopMoving();
            }
            //dispatchEvent(CameraEvent.CAMERA_UPDATE, false, this.viewport);
            dispatchEvent(new CameraEvent(CameraEvent.CAMERA_UPDATE, false, this.viewport, false));
        }