Exemplo n.º 1
0
        public virtual void advanceTime(float passedTime)
        {
            int finalFrame    = 0;
            int previousFrame = mCurrentFrame;

            if (mLoop && mCurrentTime == mTotalTime)
            {
                mCurrentTime  = 0.0f;
                mCurrentFrame = 0;
            }
            if (!mPlaying || passedTime == 0.0f || mCurrentTime == mTotalTime)
            {
                return;
            }
            mCurrentTime = mCurrentTime + passedTime;
            finalFrame   = (int)(mTextures.getLength() - 1);
            while (mCurrentTime >= mStartTimes[mCurrentFrame] + mDurations[mCurrentFrame])
            {
                if (mCurrentFrame == finalFrame)
                {
                    if (hasEventListener(AsEvent.COMPLETE))
                    {
                        float restTime = mCurrentTime - mTotalTime;
                        mCurrentTime = mTotalTime;
                        dispatchEventWith(AsEvent.COMPLETE);
                        advanceTime(restTime);
                        return;
                    }
                    if (mLoop)
                    {
                        mCurrentTime  = mCurrentTime - mTotalTime;
                        mCurrentFrame = 0;
                    }
                    else
                    {
                        mCurrentTime = mTotalTime;
                        break;
                    }
                }
                else
                {
                    mCurrentFrame++;
                    AsSound sound = mSounds[mCurrentFrame];
                    if (sound != null)
                    {
                        sound.play();
                    }
                }
            }
            if (mCurrentFrame != previousFrame)
            {
                setTexture(mTextures[mCurrentFrame]);
            }
        }
Exemplo n.º 2
0
 public AsXML this[int i]
 {
     get
     {
         if (i < mElements.getLength())
         {
             return(mElements[i]);
         }
         return(null);
     }
 }
Exemplo n.º 3
0
 private void disposeFlattenedContents()
 {
     if (mFlattenedContents != null)
     {
         int i   = 0;
         int max = (int)(mFlattenedContents.getLength());
         for (; i < max; ++i)
         {
             mFlattenedContents[i].dispose();
         }
         mFlattenedContents = null;
     }
 }
Exemplo n.º 4
0
        public void transformVectors(AsVector <float> vin, AsVector <float> vout)
        {
            int len = (int)(vin.getLength());

            if (((len % 3) != 0))
            {
                throw new AsArgumentError();
            }
            if ((len > vout.getLength()))
            {
                throw new AsArgumentError();
            }
            int i = 0;

            for (; (i < len); i = (i + 3))
            {
                float x = vin[i];
                float y = vin[i + 1];
                float z = vin[i + 2];

                vout[i]     = x * internalMatrix.M11 + y * internalMatrix.M21 + z * internalMatrix.M31 + internalMatrix.M41;
                vout[i + 1] = x * internalMatrix.M12 + y * internalMatrix.M22 + z * internalMatrix.M32 + internalMatrix.M42;
                vout[i + 2] = x * internalMatrix.M13 + y * internalMatrix.M23 + z * internalMatrix.M33 + internalMatrix.M43;
            }
        }
Exemplo n.º 5
0
        private void init(AsVector <AsTexture> textures, float fps)
        {
            if (fps <= 0)
            {
                throw new AsArgumentError("Invalid fps: " + fps);
            }
            int numFrames = (int)(textures.getLength());

            mDefaultFrameDuration = 1.0f / fps;
            mLoop         = true;
            mPlaying      = true;
            mCurrentTime  = 0.0f;
            mCurrentFrame = 0;
            mTotalTime    = mDefaultFrameDuration * numFrames;
            mTextures     = textures.concat();
            mSounds       = new AsVector <AsSound>(numFrames);
            mDurations    = new AsVector <float>(numFrames);
            mStartTimes   = new AsVector <float>(numFrames);
            int i = 0;

            for (; i < numFrames; ++i)
            {
                mDurations[i]  = mDefaultFrameDuration;
                mStartTimes[i] = i * mDefaultFrameDuration;
            }
        }
Exemplo n.º 6
0
 public virtual void removeEventListener(String type, AsEventListenerCallback listener, bool useCapture)
 {
     if (mEventListeners != null)
     {
         AsVector <AsEventListenerCallback> listeners = (AsVector <AsEventListenerCallback>)(mEventListeners[type]);
         if (listeners != null)
         {
             AsVector <AsEventListenerCallback> remainListeners   = new AsVector <AsEventListenerCallback>();
             AsVector <AsEventListenerCallback> __eventListeners_ = listeners;
             if (__eventListeners_ != null)
             {
                 foreach (AsEventListenerCallback eventListener in __eventListeners_)
                 {
                     if (eventListener != listener)
                     {
                         remainListeners.push(eventListener);
                     }
                 }
             }
             if (remainListeners.getLength() > 0)
             {
                 mEventListeners[type] = remainListeners;
             }
             else
             {
                 mEventListeners.remove(type);
             }
         }
     }
 }
Exemplo n.º 7
0
        private void createBuffers()
        {
            int         numVertices = mVertexData.getNumVertices();
            int         numIndices  = (int)(mIndexData.getLength());
            AsContext3D context     = AsStarling.getContext();

            if (mVertexBuffer != null)
            {
                mVertexBuffer.dispose();
            }
            if (mIndexBuffer != null)
            {
                mIndexBuffer.dispose();
            }
            if (numVertices == 0)
            {
                return;
            }
            if (context == null)
            {
                throw new AsMissingContextError();
            }
            mVertexBuffer = context.createVertexBuffer(numVertices, AsVertexData.ELEMENTS_PER_VERTEX);
            mVertexBuffer.uploadFromVector(mVertexData.getRawData(), 0, numVertices);
            mIndexBuffer = context.createIndexBuffer(numIndices);
            mIndexBuffer.uploadFromVector(mIndexData, 0, numIndices);
            mSyncRequired = false;
        }
        private void updatePassTextures(int width, int height, float scale)
        {
            int  numPassTextures = mNumPasses > 1 ? 2 : 1;
            bool needsUpdate     = mPassTextures == null || mPassTextures.getLength() != numPassTextures || mPassTextures[0].getWidth() != width || mPassTextures[0].getHeight() != height;

            if (needsUpdate)
            {
                if (mPassTextures != null)
                {
                    AsVector <AsTexture> __textures_ = mPassTextures;
                    if (__textures_ != null)
                    {
                        foreach (AsTexture texture in __textures_)
                        {
                            texture.dispose();
                        }
                    }
                    mPassTextures.setLength(numPassTextures);
                }
                else
                {
                    mPassTextures = new AsVector <AsTexture>(numPassTextures);
                }
                int i = 0;
                for (; i < numPassTextures; ++i)
                {
                    mPassTextures[i] = AsTexture.empty(width, height, PMA, true, scale);
                }
            }
        }
 public virtual void pushMatrix()
 {
     if (mMatrixStack.getLength() < mMatrixStackSize + 1)
     {
         mMatrixStack.push(new AsMatrix());
     }
     mMatrixStack[mMatrixStackSize++].copyFrom(mModelViewMatrix);
 }
 public virtual void pushMatrix()
 {
     if ((mMatrixStack.getLength() < (mMatrixStackSize + 1)))
     {
         mMatrixStack.push(new AsMatrix());
     }
     mMatrixStack[mMatrixStackSize++].copyFrom(mCurrentMatrix);
 }
        public virtual void broadcastEvent(AsEvent _event)
        {
            if (_event.getBubbles())
            {
                throw new AsArgumentError("Broadcast of bubbling events is prohibited");
            }
            int fromIndex = (int)(sBroadcastListeners.getLength());

            getChildEventListeners(this, _event.getType(), sBroadcastListeners);
            int toIndex = (int)(sBroadcastListeners.getLength());
            int i       = fromIndex;

            for (; i < toIndex; ++i)
            {
                sBroadcastListeners[i].dispatchEvent(_event);
            }
            sBroadcastListeners.setLength(fromIndex);
        }
Exemplo n.º 12
0
        public virtual void removeTweens(Object target)
        {
            if (target == null)
            {
                return;
            }
            int i = (int)(mObjects.getLength() - 1);

            for (; i >= 0; --i)
            {
                AsTween tween = mObjects[i] as AsTween;
                if (tween != null && tween.getTarget() == target)
                {
                    tween.removeEventListener(AsEvent.REMOVE_FROM_JUGGLER, onRemove);
                    mObjects[i] = null;
                }
            }
        }
Exemplo n.º 13
0
 public static AsEvent fromPool(String type, bool bubbles, Object data)
 {
     if (sEventPool.getLength() != 0)
     {
         return(sEventPool.pop().reset(type, bubbles, data));
     }
     else
     {
         return(new AsEvent(type, bubbles, data));
     }
 }
Exemplo n.º 14
0
 public static AsTween fromPool(Object target, float time, Object transition)
 {
     if (sTweenPool.getLength() != 0)
     {
         return(sTweenPool.pop().reset(target, time, transition));
     }
     else
     {
         return(new AsTween(target, time, transition));
     }
 }
        public override void dispatchEventOnChildren(AsEvent _event)
        {
            getChildEventListeners(this, _event.getType(), sListenersList);
            int numListeners = (int)(sListenersList.getLength());
            int i            = 0;

            for (; i < numListeners; ++i)
            {
                sListenersList[i].dispatchEvent(_event);
            }
            sListenersList.setLength(0);
        }
        public override void dispose()
        {
            int i = (int)(mChildren.getLength() - 1);

            for (; i >= 0; --i)
            {
                mChildren[i].dispose();
            }
            base.dispose();
        }
Exemplo n.º 17
0
        public virtual AsTouch getTouch(AsDisplayObject target, String phase)
        {
            AsVector <AsTouch> touchesFound = getTouches(target, phase);

            if (touchesFound.getLength() > 0)
            {
                return(touchesFound[0]);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 18
0
 public virtual AsTouch getTouch(AsDisplayObject target, String phase)
 {
     getTouches(target, phase, sTouches);
     if (sTouches.getLength() != 0)
     {
         AsTouch touch = sTouches[0];
         sTouches.setLength(0);
         return(touch);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 19
0
        public virtual void append(AsVertexData data)
        {
            mRawData.setOwnProperty("_fixed", false);
            int targetIndex          = (int)(mRawData.getLength());
            AsVector <float> rawData = data.mRawData;
            int rawDataLength        = (int)(rawData.getLength());
            int i = 0;

            for (; i < rawDataLength; ++i)
            {
                mRawData[targetIndex++] = rawData[i];
            }
            mNumVertices = mNumVertices + data.getNumVertices();
            mRawData.setOwnProperty("_fixed", true);
        }
Exemplo n.º 20
0
 public virtual void dispatch(AsVector<AsEventDispatcher> chain)
 {
     if(chain != null && chain.getLength() != 0)
     {
         int chainLength = (int)(getBubbles() ? chain.getLength() : 1);
         AsEventDispatcher previousTarget = getTarget();
         setTarget(chain[0] as AsEventDispatcher);
         int i = 0;
         for (; i < chainLength; ++i)
         {
             AsEventDispatcher chainElement = chain[i] as AsEventDispatcher;
             if(mVisitedObjects.indexOf(chainElement) == -1)
             {
                 bool stopPropagation = chainElement.invokeEvent(this);
                 mVisitedObjects.push(chainElement);
                 if(stopPropagation)
                 {
                     break;
                 }
             }
         }
         setTarget(previousTarget);
     }
 }
Exemplo n.º 21
0
 public virtual void dispatch(AsVector <AsEventDispatcher> chain)
 {
     if (chain != null && chain.getLength() != 0)
     {
         int chainLength = (int)(getBubbles() ? chain.getLength() : 1);
         AsEventDispatcher previousTarget = getTarget();
         setTarget(chain[0] as AsEventDispatcher);
         int i = 0;
         for (; i < chainLength; ++i)
         {
             AsEventDispatcher chainElement = chain[i] as AsEventDispatcher;
             if (mVisitedObjects.indexOf(chainElement) == -1)
             {
                 bool stopPropagation = chainElement.invokeEvent(this);
                 mVisitedObjects.push(chainElement);
                 if (stopPropagation)
                 {
                     break;
                 }
             }
         }
         setTarget(previousTarget);
     }
 }
        public virtual void finishQuadBatch()
        {
            AsQuadBatch currentBatch = mQuadBatches[mCurrentQuadBatchID];

            if (currentBatch.getNumQuads() != 0)
            {
                currentBatch.renderCustom(mProjectionMatrix);
                currentBatch.reset();
                ++mCurrentQuadBatchID;
                ++mDrawCount;
                if (mQuadBatches.getLength() <= mCurrentQuadBatchID)
                {
                    mQuadBatches.push(new AsQuadBatch());
                }
            }
        }
Exemplo n.º 23
0
        public virtual void dispatchEvent(AsEvent _event)
        {
            AsVector <AsEventListenerCallback> listeners = (AsVector <AsEventListenerCallback>)(mEventListeners != null ? mEventListeners[_event.getType()] : null);

            if (listeners == null && !_event.getBubbles())
            {
                return;
            }
            AsEventDispatcher previousTarget = _event.getTarget();

            if (previousTarget == null || _event.getCurrentTarget() != null)
            {
                _event.setTarget(this);
            }
            bool stopImmediatePropagation = false;
            uint numListeners             = (uint)(listeners == null ? 0 : listeners.getLength());

            if (numListeners != 0)
            {
                _event.setCurrentTarget(this);
                int i = 0;
                for (; i < numListeners; ++i)
                {
                    AsEventListenerCallback listener = listeners[i];
                    listener(_event);
                    if (_event.getStopsImmediatePropagation())
                    {
                        stopImmediatePropagation = true;
                        break;
                    }
                }
            }
            if (!stopImmediatePropagation && _event.getBubbles() && !_event.getStopsPropagation() && this is AsDisplayObject)
            {
                AsDisplayObject targetDisplayObject = this as AsDisplayObject;
                if (targetDisplayObject.getParent() != null)
                {
                    _event.setCurrentTarget(null);
                    targetDisplayObject.getParent().dispatchEvent(_event);
                }
            }
            if (previousTarget != null)
            {
                _event.setTarget(previousTarget);
            }
        }
Exemplo n.º 24
0
 public AsTouchEvent(String type, AsVector<AsTouch> touches, bool shiftKey, bool ctrlKey, bool bubbles)
     : base(type, bubbles, touches)
 {
     mShiftKey = shiftKey;
     mCtrlKey = ctrlKey;
     mTimestamp = -1.0f;
     mVisitedObjects = new AsVector<AsEventDispatcher>();
     int numTouches = (int)(touches.getLength());
     int i = 0;
     for (; i < numTouches; ++i)
     {
         if(touches[i].getTimestamp() > mTimestamp)
         {
             mTimestamp = touches[i].getTimestamp();
         }
     }
 }
 public virtual void setMatrix(AsVector <float> _value)
 {
     if (_value != null && _value.getLength() != 20)
     {
         throw new AsArgumentError("Invalid matrix length: must be 20");
     }
     if (_value == null)
     {
         mUserMatrix.setLength(0);
         mUserMatrix(IDENTITY);
     }
     else
     {
         copyMatrix(_value, mUserMatrix);
     }
     updateShaderMatrix();
 }
Exemplo n.º 26
0
 public AsTouchEvent(String type, AsVector<AsTouch> touches, bool shiftKey, bool ctrlKey, bool bubbles)
     : base(type, bubbles)
 {
     mTouches = ((touches != null) ? (touches) : (new AsVector<AsTouch>()));
     mShiftKey = shiftKey;
     mCtrlKey = ctrlKey;
     mTimestamp = -1.0f;
     int numTouches = (int)(touches.getLength());
     int i = 0;
     for (; (i < numTouches); ++i)
     {
         if((touches[i].getTimestamp() > mTimestamp))
         {
             mTimestamp = touches[i].getTimestamp();
         }
     }
 }
Exemplo n.º 27
0
        public AsTouchEvent(String type, AsVector <AsTouch> touches, bool shiftKey, bool ctrlKey, bool bubbles)
            : base(type, bubbles, touches)
        {
            mShiftKey       = shiftKey;
            mCtrlKey        = ctrlKey;
            mTimestamp      = -1.0f;
            mVisitedObjects = new AsVector <AsEventDispatcher>();
            int numTouches = (int)(touches.getLength());
            int i          = 0;

            for (; i < numTouches; ++i)
            {
                if (touches[i].getTimestamp() > mTimestamp)
                {
                    mTimestamp = touches[i].getTimestamp();
                }
            }
        }
Exemplo n.º 28
0
        public AsTouchEvent(String type, AsVector <AsTouch> touches, bool shiftKey, bool ctrlKey, bool bubbles)
            : base(type, bubbles)
        {
            mTouches   = touches != null ? touches : new AsVector <AsTouch>();
            mShiftKey  = shiftKey;
            mCtrlKey   = ctrlKey;
            mTimestamp = -1.0f;
            int numTouches = (int)(touches.getLength());
            int i          = 0;

            for (; i < numTouches; ++i)
            {
                if (touches[i].getTimestamp() > mTimestamp)
                {
                    mTimestamp = touches[i].getTimestamp();
                }
            }
        }
Exemplo n.º 29
0
        public virtual AsVector <AsTouch> getTouches(AsDisplayObject target, String phase)
        {
            AsVector <AsTouch> touchesFound = new AsVector <AsTouch>();
            int numTouches = (int)(mTouches.getLength());
            int i          = 0;

            for (; i < numTouches; ++i)
            {
                AsTouch touch         = mTouches[i];
                bool    correctTarget = (touch.getTarget() == target) || ((target is AsDisplayObjectContainer) && target as AsDisplayObjectContainer.contains(touch.getTarget()));
                bool    correctPhase  = phase == null || phase == touch.getPhase();
                if (correctTarget && correctPhase)
                {
                    touchesFound.push(touch);
                }
            }
            return(touchesFound);
        }
Exemplo n.º 30
0
        public virtual AsSprite createSprite(float width, float height, String text, float fontSize, uint color, String hAlign, String vAlign, bool autoScale, bool kerning)
        {
            AsVector <AsCharLocation> charLocations = arrangeChars(width, height, text, fontSize, hAlign, vAlign, autoScale, kerning);
            int      numChars = (int)(charLocations.getLength());
            AsSprite sprite   = new AsSprite();
            int      i        = 0;

            for (; i < numChars; ++i)
            {
                AsCharLocation charLocation = charLocations[i];
                AsImage        _char        = charLocation._char.createImage();
                _char.setX(charLocation.x);
                _char.setY(charLocation.y);
                _char.setScaleX(_char.setScaleY(charLocation.scale));
                _char.setColor(color);
                sprite.addChild(_char);
            }
            return(sprite);
        }
        private void getChildEventListeners(AsDisplayObject _object, String eventType, AsVector <AsDisplayObject> listeners)
        {
            AsDisplayObjectContainer container = _object as AsDisplayObjectContainer;

            if (_object.hasEventListener(eventType))
            {
                listeners.push(_object);
            }
            if (container != null && container.getNumChildren() > 0)
            {
                AsVector <AsDisplayObject> children = container.mChildren;
                int numChildren = (int)(children.getLength());
                int i           = 0;
                for (; i < numChildren; ++i)
                {
                    getChildEventListeners(children[i], eventType, listeners);
                }
            }
        }
Exemplo n.º 32
0
 public virtual bool interactsWith(AsDisplayObject target)
 {
     if (getTouch(target) == null)
     {
         return(false);
     }
     else
     {
         AsVector <AsTouch> touches = getTouches(target);
         int i = (int)(touches.getLength() - 1);
         for (; i >= 0; --i)
         {
             if (touches[i].getPhase() != AsTouchPhase.ENDED)
             {
                 return(true);
             }
         }
         return(false);
     }
 }
 public virtual void removeEventListener(String type, AsEventListenerCallback listener)
 {
     if (mEventListeners != null)
     {
         AsVector <AsEventListenerCallback> listeners = mEventListeners[type] as AsVector <AsEventListenerCallback>;
         if (listeners != null)
         {
             int numListeners = (int)(listeners.getLength());
             AsVector <AsEventListenerCallback> remainingListeners = new AsVector <AsEventListenerCallback>();
             int i = 0;
             for (; i < numListeners; ++i)
             {
                 if (listeners[i] != listener)
                 {
                     remainingListeners.push(listeners[i]);
                 }
             }
             mEventListeners[type] = remainingListeners;
         }
     }
 }
 public override void dispatchEventOnChildren(AsEvent _event)
 {
     AsVector<AsDisplayObject> listeners = new AsVector<AsDisplayObject>();
     getChildEventListeners(this, _event.getType(), listeners);
     int numListeners = (int)(listeners.getLength());
     int i = 0;
     for (; (i < numListeners); ++i)
     {
         listeners[i].dispatchEvent(_event);
     }
 }
Exemplo n.º 35
0
 private static int compileObject(AsDisplayObject _object, AsVector<AsQuadBatch> quadBatches, int quadBatchID, AsMatrix transformationMatrix, float alpha, String blendMode, bool ignoreCurrentFilter)
 {
     int i = 0;
     AsQuadBatch quadBatch = null;
     bool isRootObject = false;
     float objectAlpha = _object.getAlpha();
     AsDisplayObjectContainer container = _object as AsDisplayObjectContainer;
     AsQuad quad = _object as AsQuad;
     AsQuadBatch batch = _object as AsQuadBatch;
     AsFragmentFilter filter = _object.getFilter();
     if(quadBatchID == -1)
     {
         isRootObject = true;
         quadBatchID = 0;
         objectAlpha = 1.0f;
         blendMode = _object.getBlendMode();
         if(quadBatches.getLength() == 0)
         {
             quadBatches.push(new AsQuadBatch());
         }
         else
         {
             quadBatches[0].reset();
         }
     }
     if(filter != null && !ignoreCurrentFilter)
     {
         if(filter.getMode() == AsFragmentFilterMode.ABOVE)
         {
             quadBatchID = compileObject(_object, quadBatches, quadBatchID, transformationMatrix, alpha, blendMode, true);
         }
         quadBatchID = compileObject(filter.compile(_object), quadBatches, quadBatchID, transformationMatrix, alpha, blendMode);
         if(filter.getMode() == AsFragmentFilterMode.BELOW)
         {
             quadBatchID = compileObject(_object, quadBatches, quadBatchID, transformationMatrix, alpha, blendMode, true);
         }
     }
     else
     {
         if(container != null)
         {
             int numChildren = container.getNumChildren();
             AsMatrix childMatrix = new AsMatrix();
             for (i = 0; i < numChildren; ++i)
             {
                 AsDisplayObject child = container.getChildAt(i);
                 bool childVisible = child.getAlpha() != 0.0f && child.getVisible() && child.getScaleX() != 0.0f && child.getScaleY() != 0.0f;
                 if(childVisible)
                 {
                     String childBlendMode = child.getBlendMode() == AsBlendMode.AUTO ? blendMode : child.getBlendMode();
                     childMatrix.copyFrom(transformationMatrix);
                     AsRenderSupport.transformMatrixForObject(childMatrix, child);
                     quadBatchID = compileObject(child, quadBatches, quadBatchID, childMatrix, alpha * objectAlpha, childBlendMode);
                 }
             }
         }
         else
         {
             if(quad != null || batch != null)
             {
                 AsTexture texture = null;
                 String smoothing = null;
                 bool tinted = false;
                 int numQuads = 0;
                 if(quad != null)
                 {
                     AsImage image = quad as AsImage;
                     texture = image != null ? image.getTexture() : null;
                     smoothing = image != null ? image.getSmoothing() : null;
                     tinted = quad.getTinted();
                     numQuads = 1;
                 }
                 else
                 {
                     texture = batch.mTexture;
                     smoothing = batch.mSmoothing;
                     tinted = batch.mTinted;
                     numQuads = batch.mNumQuads;
                 }
                 quadBatch = quadBatches[quadBatchID];
                 if(quadBatch.isStateChange(tinted, alpha * objectAlpha, texture, smoothing, blendMode, numQuads))
                 {
                     quadBatchID++;
                     if(quadBatches.getLength() <= quadBatchID)
                     {
                         quadBatches.push(new AsQuadBatch());
                     }
                     quadBatch = quadBatches[quadBatchID];
                     quadBatch.reset();
                 }
                 if(quad != null)
                 {
                     quadBatch.addQuad(quad, alpha, texture, smoothing, transformationMatrix, blendMode);
                 }
                 else
                 {
                     quadBatch.addQuadBatch(batch, alpha, transformationMatrix, blendMode);
                 }
             }
             else
             {
                 throw new AsError("Unsupported display object: " + AsGlobal.getQualifiedClassName(_object));
             }
         }
     }
     if(isRootObject)
     {
         for (i = (int)(quadBatches.getLength() - 1); i > quadBatchID; --i)
         {
             quadBatches.pop().dispose();
         }
     }
     return quadBatchID;
 }
Exemplo n.º 36
0
 private void init(AsVector<AsTexture> textures, float fps)
 {
     if(fps <= 0)
     {
         throw new AsArgumentError("Invalid fps: " + fps);
     }
     int numFrames = (int)(textures.getLength());
     mDefaultFrameDuration = 1.0f / fps;
     mLoop = true;
     mPlaying = true;
     mCurrentTime = 0.0f;
     mCurrentFrame = 0;
     mTotalTime = mDefaultFrameDuration * numFrames;
     mTextures = textures.concat();
     mSounds = new AsVector<AsSound>(numFrames);
     mDurations = new AsVector<float>(numFrames);
     mStartTimes = new AsVector<float>(numFrames);
     int i = 0;
     for (; i < numFrames; ++i)
     {
         mDurations[i] = mDefaultFrameDuration;
         mStartTimes[i] = i * mDefaultFrameDuration;
     }
 }
Exemplo n.º 37
0
        public void transformVectors(AsVector<float> vin, AsVector<float> vout)
        {
            int len = (int)(vin.getLength());
            if (((len % 3) != 0))
            {
                throw new AsArgumentError();
            }
            if ((len > vout.getLength()))
            {
                throw new AsArgumentError();
            }
            int i = 0;
            for (; (i < len); i = (i + 3))
            {
                float x = vin[i];
                float y = vin[i + 1];
                float z = vin[i + 2];

                vout[i] = x * internalMatrix.M11 + y * internalMatrix.M21 + z * internalMatrix.M31 + internalMatrix.M41;
                vout[i + 1] = x * internalMatrix.M12 + y * internalMatrix.M22 + z * internalMatrix.M32 + internalMatrix.M42;
                vout[i + 2] = x * internalMatrix.M13 + y * internalMatrix.M23 + z * internalMatrix.M33 + internalMatrix.M43;
            }
        }
 public virtual void setMatrix(AsVector<float> _value)
 {
     if(_value != null && _value.getLength() != 20)
     {
         throw new AsArgumentError("Invalid matrix length: must be 20");
     }
     if(_value == null)
     {
         mUserMatrix.setLength(0);
         mUserMatrix(IDENTITY);
     }
     else
     {
         copyMatrix(_value, mUserMatrix);
     }
     updateShaderMatrix();
 }
Exemplo n.º 39
0
 private AsVector<AsCharLocation> arrangeChars(float width, float height, String text, float fontSize, String hAlign, String vAlign, bool autoScale, bool kerning)
 {
     if(text == null || text.Length == 0)
     {
         return new AsVector<AsCharLocation>();
     }
     if(fontSize < 0)
     {
         fontSize = fontSize * -mSize;
     }
     AsVector<AsVector<AsCharLocation>> lines = null;
     bool finished = false;
     AsCharLocation charLocation = null;
     int numChars = 0;
     float containerWidth = 0;
     float containerHeight = 0;
     float scale = 0;
     while(!finished)
     {
         scale = fontSize / mSize;
         containerWidth = width / scale;
         containerHeight = height / scale;
         lines = new AsVector<AsVector<AsCharLocation>>();
         if(mLineHeight <= containerHeight)
         {
             int lastWhiteSpace = -1;
             int lastCharID = -1;
             float currentX = 0;
             float currentY = 0;
             AsVector<AsCharLocation> currentLine = new AsVector<AsCharLocation>();
             numChars = text.Length;
             int i = 0;
             for (; i < numChars; ++i)
             {
                 bool lineFull = false;
                 int charID = (int)(AsString.charCodeAt(text, i));
                 AsBitmapChar _char = getChar(charID);
                 if(charID == CHAR_NEWLINE || charID == CHAR_CARRIAGE_RETURN)
                 {
                     lineFull = true;
                 }
                 else
                 {
                     if(_char == null)
                     {
                         AsGlobal.trace("[Starling] Missing character: " + charID);
                     }
                     else
                     {
                         if(charID == CHAR_SPACE || charID == CHAR_TAB)
                         {
                             lastWhiteSpace = i;
                         }
                         if(kerning)
                         {
                             currentX = currentX + _char.getKerning(lastCharID);
                         }
                         charLocation = mCharLocationPool.getLength() != 0 ? mCharLocationPool.pop() : new AsCharLocation(_char);
                         charLocation._char = _char;
                         charLocation.x = currentX + _char.getXOffset();
                         charLocation.y = currentY + _char.getYOffset();
                         currentLine.push(charLocation);
                         currentX = currentX + _char.getXAdvance();
                         lastCharID = charID;
                         if(currentLine.getLength() == 1)
                         {
                             currentX = currentX - _char.getXOffset();
                             charLocation.x = charLocation.x - _char.getXOffset();
                         }
                         if(charLocation.x + _char.getWidth() > containerWidth)
                         {
                             int numCharsToRemove = lastWhiteSpace == -1 ? 1 : i - lastWhiteSpace;
                             int removeIndex = (int)(currentLine.getLength() - numCharsToRemove);
                             currentLine.splice(removeIndex, (uint)(numCharsToRemove));
                             if(currentLine.getLength() == 0)
                             {
                                 break;
                             }
                             i = i - numCharsToRemove;
                             lineFull = true;
                         }
                     }
                 }
                 if(i == numChars - 1)
                 {
                     lines.push(currentLine);
                     finished = true;
                 }
                 else
                 {
                     if(lineFull)
                     {
                         lines.push(currentLine);
                         if(lastWhiteSpace == i)
                         {
                             currentLine.pop();
                         }
                         if(currentY + 2 * mLineHeight <= containerHeight)
                         {
                             currentLine = new AsVector<AsCharLocation>();
                             currentX = 0;
                             currentY = currentY + mLineHeight;
                             lastWhiteSpace = -1;
                             lastCharID = -1;
                         }
                         else
                         {
                             break;
                         }
                     }
                 }
             }
         }
         if(autoScale && !finished)
         {
             fontSize = fontSize - 1;
             lines.setLength(0);
         }
         else
         {
             finished = true;
         }
     }
     AsVector<AsCharLocation> finalLocations = new AsVector<AsCharLocation>();
     int numLines = (int)(lines.getLength());
     float bottom = currentY + mLineHeight;
     int yOffset = 0;
     if(vAlign == AsVAlign.BOTTOM)
     {
         yOffset = (int)(containerHeight - bottom);
     }
     else
     {
         if(vAlign == AsVAlign.CENTER)
         {
             yOffset = (int)((containerHeight - bottom) / 2);
         }
     }
     int lineID = 0;
     for (; lineID < numLines; ++lineID)
     {
         AsVector<AsCharLocation> line = lines[lineID];
         numChars = (int)(line.getLength());
         if(numChars == 0)
         {
             continue;
         }
         AsCharLocation lastLocation = line[line.getLength() - 1];
         float right = lastLocation.x + lastLocation._char.getWidth();
         int xOffset = 0;
         if(hAlign == AsHAlign.RIGHT)
         {
             xOffset = (int)(containerWidth - right);
         }
         else
         {
             if(hAlign == AsHAlign.CENTER)
             {
                 xOffset = (int)((containerWidth - right) / 2);
             }
         }
         int c = 0;
         for (; c < numChars; ++c)
         {
             charLocation = line[c];
             charLocation.x = scale * (charLocation.x + xOffset);
             charLocation.y = scale * (charLocation.y + yOffset);
             charLocation.scale = scale;
             if(charLocation._char.getWidth() > 0 && charLocation._char.getHeight() > 0)
             {
                 finalLocations.push(charLocation);
             }
             mCharLocationPool.push(charLocation);
         }
     }
     return finalLocations;
 }
 public virtual void removeEventListener(String type, AsEventListenerCallback listener)
 {
     if(mEventListeners != null)
     {
         AsVector<AsEventListenerCallback> listeners = (AsVector<AsEventListenerCallback>)(mEventListeners[type]);
         if(listeners != null)
         {
             AsVector<AsEventListenerCallback> remainListeners = new AsVector<AsEventListenerCallback>();
             AsVector<AsEventListenerCallback> __eventListeners_ = listeners;
             if (__eventListeners_ != null)
             {
                 foreach (AsEventListenerCallback eventListener in __eventListeners_)
                 {
                     if((eventListener != listener))
                     {
                         remainListeners.push(eventListener);
                     }
                 }
             }
             if((remainListeners.getLength() > 0))
             {
                 mEventListeners[type] = remainListeners;
             }
             else
             {
                 mEventListeners.remove(type);
             }
         }
     }
 }