public AsFragmentFilter(int numPasses, float resolution) { if (AsCapabilities.getIsDebugger() && AsGlobal.getQualifiedClassName(this) == "starling.filters::FragmentFilter") { throw new AsAbstractClassError(); } if (numPasses < 1) { throw new AsArgumentError("At least one pass is required."); } mNumPasses = numPasses; mMarginX = mMarginY = 0.0f; mOffsetX = mOffsetY = 0; mResolution = resolution; mMode = AsFragmentFilterMode.REPLACE; mVertexData = new AsVertexData(4); mVertexData.setTexCoords(0, 0, 0); mVertexData.setTexCoords(1, 1, 0); mVertexData.setTexCoords(2, 0, 1); mVertexData.setTexCoords(3, 1, 1); mIndexData = new AsVector <uint>(); mIndexData.setOwnProperty("_fixed", true); createPrograms(); AsStarling.getCurrent().getStage3D().addEventListener(AsEvent.CONTEXT3D_CREATE, onContextCreated, false, 0, true); }
public AsDisplayObjectContainer() { if (AsGlobal.getQualifiedClassName(this) == "DisplayObjectContainer") { throw new AsAbstractClassError(); } }
public static AsTexture empty(int width, int height, bool premultipliedAlpha, bool optimizeForRenderTexture, float scale) { if (scale <= 0) { scale = AsStarling.getContentScaleFactor(); } int origWidth = (int)(width * scale); int origHeight = (int)(height * scale); int legalWidth = AsGlobal.getNextPowerOfTwo(origWidth); int legalHeight = AsGlobal.getNextPowerOfTwo(origHeight); String format = AsContext3DTextureFormat.BGRA; AsContext3D context = AsStarling.getContext(); if (context == null) { throw new AsMissingContextError(); } bc.flash.display3D.textures.AsTexture nativeTexture = context.createTexture(legalWidth, legalHeight, AsContext3DTextureFormat.BGRA, optimizeForRenderTexture); AsConcreteTexture concreteTexture = new AsConcreteTexture(nativeTexture, format, legalWidth, legalHeight, false, premultipliedAlpha, optimizeForRenderTexture, scale); if (origWidth == legalWidth && origHeight == legalHeight) { return(concreteTexture); } else { return(new AsSubTexture(concreteTexture, new AsRectangle(0, 0, width, height), true)); } }
public AsTexture() { if (AsCapabilities.getIsDebugger() && AsGlobal.getQualifiedClassName(this) == "starling.textures::Texture") { throw new AsAbstractClassError(); } mRepeat = false; }
private void initialize() { makeCurrent(); initializeGraphicsAPI(); initializeRoot(); mTouchProcessor.setSimulateMultitouch(mSimulateMultitouch); mLastFrameTimestamp = AsGlobal.getTimer() / 1000.0f; }
public AsDisplayObjectContainer() { if (AsCapabilities.getIsDebugger() && AsGlobal.getQualifiedClassName(this) == "starling.display::DisplayObjectContainer") { throw new AsAbstractClassError(); } mChildren = new AsVector <AsDisplayObject>(); }
public virtual void nextFrame() { float now = AsGlobal.getTimer() / 1000.0f; float passedTime = now - mLastFrameTimestamp; mLastFrameTimestamp = now; advanceTime(passedTime); render(); }
private void initializeGraphicsAPI() { mContext = mStage3D.getContext3D(); mContext.setEnableErrorChecking(mEnableErrorChecking); mPrograms = new AsDictionary(); updateViewPort(); AsGlobal.trace("[Starling] Initialization complete."); AsGlobal.trace("[Starling] Display Driver:", mContext.getDriverInfo()); dispatchEventWith(starling.events.Event.CONTEXT3D_CREATE, false, mContext); }
private void parseFontXml(AsXML fontXml) { float scale = mTexture.getScale(); AsRectangle frame = mTexture.getFrame(); mName = fontXml.elements("info").attribute("face"); mSize = AsGlobal.parseFloat(fontXml.elements("info").attribute("size")) / scale; mLineHeight = AsGlobal.parseFloat(fontXml.elements("common").attribute("lineHeight")) / scale; mBaseline = AsGlobal.parseFloat(fontXml.elements("common").attribute("base")) / scale; if (fontXml.elements("info").attribute("smooth").ToString() == "0") { setSmoothing(AsTextureSmoothing.NONE); } if (mSize <= 0) { AsGlobal.trace("[Starling] Warning: invalid font size in '" + mName + "' font."); mSize = mSize == 0.0f ? 16.0f : mSize * -1.0f; } AsXMLList __charElements_ = fontXml.elements("chars").elements("_char"); if (__charElements_ != null) { foreach (AsXML charElement in __charElements_) { int id = (int)(AsGlobal.parseInt(charElement.attribute("id"))); float xOffset = AsGlobal.parseFloat(charElement.attribute("xoffset")) / scale; float yOffset = AsGlobal.parseFloat(charElement.attribute("yoffset")) / scale; float xAdvance = AsGlobal.parseFloat(charElement.attribute("xadvance")) / scale; AsRectangle region = new AsRectangle(); region.x = AsGlobal.parseFloat(charElement.attribute("x")) / scale + frame.x; region.y = AsGlobal.parseFloat(charElement.attribute("y")) / scale + frame.y; region.width = AsGlobal.parseFloat(charElement.attribute("width")) / scale; region.height = AsGlobal.parseFloat(charElement.attribute("height")) / scale; AsTexture texture = AsTexture.fromTexture(mTexture, region); AsBitmapChar bitmapChar = new AsBitmapChar(id, texture, xOffset, yOffset, xAdvance); addChar(id, bitmapChar); } } AsXMLList __kerningElements_ = fontXml.elements("kernings").elements("kerning"); if (__kerningElements_ != null) { foreach (AsXML kerningElement in __kerningElements_) { int first = (int)(AsGlobal.parseInt(kerningElement.attribute("first"))); int second = (int)(AsGlobal.parseInt(kerningElement.attribute("second"))); float amount = AsGlobal.parseFloat(kerningElement.attribute("amount")) / scale; if (mChars.containsKey(second)) { getChar(second).addKerning(first, amount); } } } }
public AsDisplayObject() { if (AsGlobal.getQualifiedClassName(this) == "starling.display::DisplayObject") { throw new AsAbstractClassError(); } mX = mY = mPivotX = mPivotY = mRotation = 0.0f; mScaleX = mScaleY = mAlpha = 1.0f; mVisible = mTouchable = true; mLastTouchTimestamp = -1; mTransform = new AsTransform(this); }
public AsDisplayObject() { if (AsCapabilities.getIsDebugger() && AsGlobal.getQualifiedClassName(this) == "starling.display::DisplayObject") { throw new AsAbstractClassError(); } mX = mY = mPivotX = mPivotY = mRotation = mSkewX = mSkewY = 0.0f; mScaleX = mScaleY = mAlpha = 1.0f; mVisible = mTouchable = true; mBlendMode = AsBlendMode.AUTO; mTransformationMatrix = new AsMatrix(); mOrientationChanged = mUseHandCursor = false; }
public override AsRectangle getBounds(AsDisplayObject targetSpace, AsRectangle resultRect) { if ((resultRect == null)) { resultRect = new AsRectangle(); } if ((targetSpace == this)) { resultRect.x = getX(); resultRect.y = getY(); resultRect.width = mBitmapData.getWidth(); resultRect.height = mBitmapData.getHeight(); return(resultRect); } float minX = AsMathHelper.MAX_NUMBER; float maxX = -AsMathHelper.MAX_NUMBER; float minY = AsMathHelper.MAX_NUMBER; float maxY = -AsMathHelper.MAX_NUMBER; getTransformationMatrix(targetSpace, sHelperMatrix); sPosition.x = getX(); sPosition.y = getY(); AsGlobal.transformCoords(sHelperMatrix, sPosition.x, sPosition.y, sHelperPoint); minX = (((minX < sHelperPoint.x)) ? (minX) : (sHelperPoint.x)); maxX = (((maxX > sHelperPoint.x)) ? (maxX) : (sHelperPoint.x)); minY = (((minY < sHelperPoint.y)) ? (minY) : (sHelperPoint.y)); maxY = (((maxY > sHelperPoint.y)) ? (maxY) : (sHelperPoint.y)); sPosition.x = (sPosition.x + getBitmapData().getWidth()); AsGlobal.transformCoords(sHelperMatrix, sPosition.x, sPosition.y, sHelperPoint); minX = (((minX < sHelperPoint.x)) ? (minX) : (sHelperPoint.x)); maxX = (((maxX > sHelperPoint.x)) ? (maxX) : (sHelperPoint.x)); minY = (((minY < sHelperPoint.y)) ? (minY) : (sHelperPoint.y)); maxY = (((maxY > sHelperPoint.y)) ? (maxY) : (sHelperPoint.y)); sPosition.y = (sPosition.y + getBitmapData().getHeight()); AsGlobal.transformCoords(sHelperMatrix, sPosition.x, sPosition.y, sHelperPoint); minX = (((minX < sHelperPoint.x)) ? (minX) : (sHelperPoint.x)); maxX = (((maxX > sHelperPoint.x)) ? (maxX) : (sHelperPoint.x)); minY = (((minY < sHelperPoint.y)) ? (minY) : (sHelperPoint.y)); maxY = (((maxY > sHelperPoint.y)) ? (maxY) : (sHelperPoint.y)); sPosition.x = getX(); AsGlobal.transformCoords(sHelperMatrix, sPosition.x, sPosition.y, sHelperPoint); minX = (((minX < sHelperPoint.x)) ? (minX) : (sHelperPoint.x)); maxX = (((maxX > sHelperPoint.x)) ? (maxX) : (sHelperPoint.x)); minY = (((minY < sHelperPoint.y)) ? (minY) : (sHelperPoint.y)); maxY = (((maxY > sHelperPoint.y)) ? (maxY) : (sHelperPoint.y)); resultRect.x = minX; resultRect.y = minY; resultRect.width = (maxX - minX); resultRect.height = (maxY - minY); return(resultRect); }
private void onContextCreated(AsEvent _event) { if (!AsStarling.getHandleLostContext() && mContext != null) { stop(); _event.stopImmediatePropagation(); showFatalError("Fatal error: The application lost the device context!"); AsGlobal.trace("[Starling] The device context was lost. " + "Enable 'Starling.handleLostContext' to avoid this error."); } else { initialize(); } }
public AsRenderTexture(int width, int height, bool persistent, float scale) : base(mActiveTexture = AsTexture.empty(width, height, PMA, true, scale = scale <= 0 ? AsStarling.getContentScaleFactor() : scale), new AsRectangle(0, 0, width, height), true) { int nativeWidth = AsGlobal.getNextPowerOfTwo((int)(width * scale)); int nativeHeight = AsGlobal.getNextPowerOfTwo((int)(height * scale)); mSupport = new AsRenderSupport(); mSupport.setOrthographicProjection(0, 0, nativeWidth / scale, nativeHeight / scale); if (persistent) { mBufferTexture = AsTexture.empty(width, height, PMA, true, scale); mHelperImage = new AsImage(mBufferTexture); mHelperImage.setSmoothing(AsTextureSmoothing.NONE); } }
public override AsRectangle getBounds(AsDisplayObject targetSpace, AsRectangle resultRect) { if (resultRect == null) { resultRect = new AsRectangle(); } int childsCount = getNumChildren(); if (childsCount == 0) { getTransformationMatrix(targetSpace, sHelperMatrix); AsGlobal.transformCoords(sHelperMatrix, 0.0f, 0.0f, sHelperPoint); resultRect.x = sHelperPoint.x; resultRect.y = sHelperPoint.y; resultRect.width = resultRect.height = 0; return(resultRect); } else { if (childsCount == 1) { return(mChildren[0].getBounds(targetSpace, resultRect)); } else { float minX = AsMathHelper.MAX_NUMBER; float maxX = -AsMathHelper.MAX_NUMBER; float minY = AsMathHelper.MAX_NUMBER; float maxY = -AsMathHelper.MAX_NUMBER; int i = 0; for (; i < childsCount; ++i) { mChildren[i].getBounds(targetSpace, resultRect); minX = minX < resultRect.x ? minX : resultRect.x; maxX = maxX > resultRect.getRight() ? maxX : resultRect.getRight(); minY = minY < resultRect.y ? minY : resultRect.y; maxY = maxY > resultRect.getBottom() ? maxY : resultRect.getBottom(); } resultRect.x = minX; resultRect.y = minY; resultRect.width = maxX - minX; resultRect.height = maxY - minY; return(resultRect); } } }
public static AsTexture fromBitmapData(AsBitmapData data, bool generateMipMaps, bool optimizeForRenderTexture, float scale) { int origWidth = data.getWidth(); int origHeight = data.getHeight(); int legalWidth = AsGlobal.getNextPowerOfTwo(origWidth); int legalHeight = AsGlobal.getNextPowerOfTwo(origHeight); AsContext3D context = AsStarling.getContext(); AsBitmapData potData = null; if (context == null) { throw new AsMissingContextError(); } bc.flash.display3D.textures.AsTexture nativeTexture = context.createTexture(legalWidth, legalHeight, AsContext3DTextureFormat.BGRA, optimizeForRenderTexture); if (legalWidth > origWidth || legalHeight > origHeight) { potData = new AsBitmapData(legalWidth, legalHeight, true, 0); potData.copyPixels(data, data.getRect(), sOrigin); data = potData; } uploadBitmapData(nativeTexture, data, generateMipMaps); AsConcreteTexture concreteTexture = new AsConcreteTexture(nativeTexture, AsContext3DTextureFormat.BGRA, legalWidth, legalHeight, generateMipMaps, true, optimizeForRenderTexture, scale); if (AsStarling.getHandleLostContext()) { concreteTexture.restoreOnLostContext(data); } else { if (potData != null) { potData.dispose(); } } if (origWidth == legalWidth && origHeight == legalHeight) { return(concreteTexture); } else { return(new AsSubTexture(concreteTexture, new AsRectangle(0, 0, origWidth / scale, origHeight / scale), true)); } }
private void calculateBounds(AsDisplayObject _object, AsStage stage, AsRectangle resultRect) { if (_object == stage || _object == AsStarling.getCurrent().getRoot()) { resultRect.setTo(0, 0, stage.getStageWidth(), stage.getStageHeight()); } else { _object.getBounds(stage, resultRect); } float deltaMargin = mResolution == 1.0f ? 0.0f : 1.0f / mResolution; resultRect.x = resultRect.x - mMarginX + deltaMargin; resultRect.y = resultRect.y - mMarginY + deltaMargin; resultRect.width = resultRect.width + 2 * (mMarginX + deltaMargin); resultRect.height = resultRect.height + 2 * (mMarginY + deltaMargin); resultRect.width = AsGlobal.getNextPowerOfTwo((int)(resultRect.width * mResolution)) / mResolution; resultRect.height = AsGlobal.getNextPowerOfTwo((int)(resultRect.height * mResolution)) / mResolution; }
public override AsDisplayObject hitTest(AsPoint localPoint, bool forTouch) { if (forTouch && (!getVisible() || !getTouchable())) { return(null); } float localX = localPoint.x; float localY = localPoint.y; int childsCount = getNumChildren(); int i = childsCount - 1; for (; i >= 0; --i) { AsDisplayObject child = mChildren[i]; getTransformationMatrix(child, sHelperMatrix); AsGlobal.transformCoords(sHelperMatrix, localX, localY, sHelperPoint); AsDisplayObject target = child.hitTest(sHelperPoint, forTouch); if (target != null) { return(target); } } return(null); }
protected virtual void parseAtlasXml(AsXML atlasXml) { float scale = mAtlasTexture.getScale(); AsSubTexture __subTextures_ = atlasXml.SubTexture; if (__subTextures_ != null) { foreach (AsXML subTexture in __subTextures_) { String name = subTexture.attribute("name"); float x = AsGlobal.parseFloat(subTexture.attribute("x")) / scale; float y = AsGlobal.parseFloat(subTexture.attribute("y")) / scale; float width = AsGlobal.parseFloat(subTexture.attribute("width")) / scale; float height = AsGlobal.parseFloat(subTexture.attribute("height")) / scale; float frameX = AsGlobal.parseFloat(subTexture.attribute("frameX")) / scale; float frameY = AsGlobal.parseFloat(subTexture.attribute("frameY")) / scale; float frameWidth = AsGlobal.parseFloat(subTexture.attribute("frameWidth")) / scale; float frameHeight = AsGlobal.parseFloat(subTexture.attribute("frameHeight")) / scale; AsRectangle region = new AsRectangle(x, y, width, height); AsRectangle frame = frameWidth > 0 && frameHeight > 0 ? new AsRectangle(frameX, frameY, frameWidth, frameHeight) : null; addRegion(name, region, frame); } } }
public virtual String toString() { return(AsGlobal.formatString("[{0} type=\"{1}\" bubbles={2}]", (As_AS_REST)(AsString.split(AsGlobal.getQualifiedClassName(this), "::").pop()), mType, mBubbles)); }
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); }
public virtual String toString() { return(AsGlobal.formatString("Touch {0}: globalX={1}, globalY={2}, phase={3}", mID, mGlobalX, mGlobalY, mPhase)); }
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 start() { mStarted = true; mLastFrameTimestamp = AsGlobal.getTimer() / 1000.0f; }
public virtual void advanceTime(float time) { if (time == 0 || (mRepeatCount == 1 && mCurrentTime == mTotalTime)) { return; } int i = 0; float previousTime = mCurrentTime; float restTime = mTotalTime - mCurrentTime; float carryOverTime = time > restTime ? time - restTime : 0.0f; mCurrentTime = AsMath.min(mTotalTime, mCurrentTime + time); if (mCurrentTime <= 0) { return; } if (mCurrentCycle < 0 && previousTime <= 0 && mCurrentTime > 0) { mCurrentCycle++; if (mOnStart != null) { mOnStart((float)(mOnStartArgs[0])); } } float ratio = mCurrentTime / mTotalTime; bool reversed = mReverse && (mCurrentCycle % 2 == 1); int numProperties = (int)(mStartValues.getLength()); for (i = 0; i < numProperties; ++i) { if (AsGlobal.isNaN(mStartValues[i])) { mStartValues[i] = ((AsObject)(mTarget)).getOwnProperty(mProperties[i]) as float; } float startValue = mStartValues[i]; float endValue = mEndValues[i]; float delta = endValue - startValue; float transitionValue = reversed ? mTransitionFunc(1.0f - ratio) : mTransitionFunc(ratio); float currentValue = startValue + transitionValue * delta; if (mRoundToInt) { currentValue = AsMath.round(currentValue); } ((AsObject)(mTarget)).setOwnProperty(mProperties[i], currentValue); } if (mOnUpdate != null) { mOnUpdate((float)(mOnUpdateArgs[0])); } if (previousTime < mTotalTime && mCurrentTime >= mTotalTime) { if (mRepeatCount == 0 || mRepeatCount > 1) { mCurrentTime = -mRepeatDelay; mCurrentCycle++; if (mRepeatCount > 1) { mRepeatCount--; } if (mOnRepeat != null) { mOnRepeat((float)(mOnRepeatArgs[0])); } } else { AsTransitionCallback onComplete = mOnComplete; AsArray onCompleteArgs = mOnCompleteArgs; dispatchEventWith(AsEvent.REMOVE_FROM_JUGGLER); if (onComplete != null) { onComplete((float)(onCompleteArgs[0])); } } } if (carryOverTime != 0) { advanceTime(carryOverTime); } }
public AsStarling(AsClass rootClass, bc.flash.display.AsStage stage, AsRectangle viewPort, AsStage3D stage3D, String renderMode, String profile) { if (stage == null) { throw new AsArgumentError("Stage must not be null"); } if (rootClass == null) { throw new AsArgumentError("Root class must not be null"); } if (viewPort == null) { viewPort = new AsRectangle(0, 0, stage.getStageWidth(), stage.getStageHeight()); } if (stage3D == null) { stage3D = stage.getStage3Ds()[0]; } makeCurrent(); mRootClass = rootClass; mViewPort = viewPort; mStage3D = stage3D; mStage = new AsStage(viewPort.width, viewPort.height, stage.getColor()); mNativeOverlay = new AsSprite(); mNativeStage = stage; mNativeStage.addChild(mNativeOverlay); mTouchProcessor = new AsTouchProcessor(mStage); mJuggler = new AsJuggler(); mAntiAliasing = 0; mSimulateMultitouch = false; mEnableErrorChecking = false; mLastFrameTimestamp = AsGlobal.getTimer() / 1000.0f; mPrograms = new AsDictionary(); mCustomData = new AsDictionary(); mSupport = new AsRenderSupport(); AsArray __touchEventTypes_ = getTouchEventTypes(); if (__touchEventTypes_ != null) { foreach (String touchEventType in __touchEventTypes_) { stage.addEventListener(touchEventType, onTouch, false, 0, true); } } stage.addEventListener(AsEvent.ENTER_FRAME, onEnterFrame, false, 0, true); stage.addEventListener(AsKeyboardEvent.KEY_DOWN, onKey, false, 0, true); stage.addEventListener(AsKeyboardEvent.KEY_UP, onKey, false, 0, true); stage.addEventListener(AsEvent.RESIZE, onResize, false, 0, true); if (mStage3D.getContext3D() != null && mStage3D.getContext3D().getDriverInfo() != "Disposed") { mShareContext = true; AsGlobal.setTimeout(initialize, 1); } else { mShareContext = false; mStage3D.addEventListener(AsEvent.CONTEXT3D_CREATE, onContextCreated, false, 1, true); mStage3D.addEventListener(AsErrorEvent.ERROR, onStage3DError, false, 1, true); try { mStage3D.requestContext3D(renderMode); } catch (AsError e) { showFatalError("Context3D error: " + e.message); } } }