Skip to content

Commit

Permalink
升级Starling1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zmLiu committed Jan 22, 2015
1 parent 577370a commit e90e69e
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 84 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ StarlingFeathers
================

#####整合Starling+Feathers 还有一些Starling扩展
#####Starling 1.6RC + Feathers 2.0.1
#####Starling 1.6.1 + Feathers 2.0.1

Starling源码的优化
================
Expand Down
2 changes: 1 addition & 1 deletion StarlingFeathers/src/starling/animation/Juggler.as
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ package starling.animation
{
if (object && mObjects.indexOf(object) == -1)
{
mObjects.push(object);
mObjects[mObjects.length] = object;

var dispatcher:EventDispatcher = object as EventDispatcher;
if (dispatcher) dispatcher.addEventListener(Event.REMOVE_FROM_JUGGLER, onRemove);
Expand Down
6 changes: 3 additions & 3 deletions StarlingFeathers/src/starling/animation/Tween.as
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ package starling.animation
{
if (mTarget == null) return; // tweening null just does nothing.

mProperties.push(property);
mStartValues.push(Number.NaN);
mEndValues.push(endValue);
mProperties[mProperties.length] = property;
mStartValues[mStartValues.length] = Number.NaN;
mEndValues[mEndValues.length] = endValue;
}

/** Animates the 'scaleX' and 'scaleY' properties of an object simultaneously. */
Expand Down
11 changes: 6 additions & 5 deletions StarlingFeathers/src/starling/core/Starling.as
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ package starling.core
public class Starling extends EventDispatcher
{
/** The version of the Starling framework. */
public static const VERSION:String = "1.6";
public static const VERSION:String = "1.6.1";

/** The key for the shader programs stored in 'contextData' */
private static const PROGRAM_DATA_NAME:String = "Starling.programs";
Expand Down Expand Up @@ -217,7 +217,7 @@ package starling.core
private var mNativeStageContentScaleFactor:Number;

private static var sCurrent:Starling;
private static var sHandleLostContext:Boolean;
private static var sHandleLostContext:Boolean = true;
private static var sContextData:Dictionary = new Dictionary(true);
private static var sAll:Vector.<Starling> = new <Starling>[];

Expand Down Expand Up @@ -360,7 +360,7 @@ package starling.core
var currentProfile:String;

if (profile == "auto")
profiles = ["standard", "baselineExtended", "baseline", "baselineConstrained"];
profiles = ["standard", "standardConstrained", "baselineExtended", "baseline", "baselineConstrained"];
else if (profile is String)
profiles = [profile as String];
else if (profile is Array)
Expand Down Expand Up @@ -492,7 +492,6 @@ package starling.core

makeCurrent();
updateViewPort();
updateNativeOverlay();
mSupport.nextFrame();

var scaleX:Number = mViewPort.width / mStage.stageWidth;
Expand Down Expand Up @@ -675,14 +674,16 @@ package starling.core

private function onEnterFrame(event:Event):void
{
// On mobile, the native display list is only updated on stage3D draw calls.
// On mobile, the native display list is only updated on stage3D draw calls.
// Thus, we render even when Starling is paused.

if (!mShareContext)
{
if (mStarted) nextFrame();
else if (mRendering) render();
}

updateNativeOverlay();
}

private function onKey(event:KeyboardEvent):void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,5 @@ package starling.display
// mChildren.splice(0,length);
mChildren = new <DisplayObject>[];
}

}
}
29 changes: 22 additions & 7 deletions StarlingFeathers/src/starling/display/Sprite3D.as
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ package starling.display
/** @inheritDoc */
public override function render(support:RenderSupport, parentAlpha:Number):void
{
if (is2D) super.render(support, parentAlpha)
if (is2D) super.render(support, parentAlpha);
else
{
support.finishQuadBatch();
Expand Down Expand Up @@ -167,13 +167,28 @@ package starling.display

private function updateMatrices():void
{
var x:Number = this.x;
var y:Number = this.y;
var scaleX:Number = this.scaleX;
var scaleY:Number = this.scaleY;
var pivotX:Number = this.pivotX;
var pivotY:Number = this.pivotY;
var rotationZ:Number = this.rotation;

mTransformationMatrix3D.identity();
mTransformationMatrix3D.appendScale(scaleX || E , scaleY || E, mScaleZ || E);
mTransformationMatrix3D.appendRotation(rad2deg(mRotationX), Vector3D.X_AXIS);
mTransformationMatrix3D.appendRotation(rad2deg(mRotationY), Vector3D.Y_AXIS);
mTransformationMatrix3D.appendRotation(rad2deg( rotation ), Vector3D.Z_AXIS);
mTransformationMatrix3D.appendTranslation(x, y, mZ);
mTransformationMatrix3D.prependTranslation(-pivotX, -pivotY, -mPivotZ);

if (scaleX != 1.0 || scaleY != 1.0 || mScaleZ != 1.0)
mTransformationMatrix3D.appendScale(scaleX || E , scaleY || E, mScaleZ || E);
if (mRotationX != 0.0)
mTransformationMatrix3D.appendRotation(rad2deg(mRotationX), Vector3D.X_AXIS);
if (mRotationY != 0.0)
mTransformationMatrix3D.appendRotation(rad2deg(mRotationY), Vector3D.Y_AXIS);
if (rotationZ != 0.0)
mTransformationMatrix3D.appendRotation(rad2deg( rotationZ), Vector3D.Z_AXIS);
if (x != 0.0 || y != 0.0 || mZ != 0.0)
mTransformationMatrix3D.appendTranslation(x, y, mZ);
if (pivotX != 0.0 || pivotY != 0.0 || mPivotZ != 0.0)
mTransformationMatrix3D.prependTranslation(-pivotX, -pivotY, -mPivotZ);

if (is2D) MatrixUtil.convertTo2D(mTransformationMatrix3D, mTransformationMatrix);
else mTransformationMatrix.identity();
Expand Down
4 changes: 2 additions & 2 deletions StarlingFeathers/src/starling/events/EventDispatcher.as
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ package starling.events
if (listeners == null)
mEventListeners[type] = new <Function>[listener];
else if (listeners.indexOf(listener) == -1) // check for duplicates
listeners.push(listener);
listeners[listeners.length] = listener; // avoid 'push'
}

/** Removes an event listener from the object. */
Expand Down Expand Up @@ -181,7 +181,7 @@ package starling.events
}

chain.length = 0;
sBubbleChains.push(chain);
sBubbleChains[sBubbleChains.length] = chain; // avoid 'push'
}

/** Dispatches an event with the given parameters to all objects that have registered
Expand Down
4 changes: 2 additions & 2 deletions StarlingFeathers/src/starling/filters/ColorMatrixFilter.as
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ package starling.filters
/** Tints the image in a certain color, analog to what can be done in Flash Pro.
* @param color the RGB color with which the image should be tinted.
* @param amount the intensity with which tinting should be applied. Range (0, 1). */
public function tint(color:uint, amount:Number=1.0):void
public function tint(color:uint, amount:Number=1.0):ColorMatrixFilter
{
var r:Number = Color.getRed(color) / 255.0;
var g:Number = Color.getGreen(color) / 255.0;
Expand All @@ -189,7 +189,7 @@ package starling.filters
var gA:Number = amount * g;
var bA:Number = amount * b;

concatValues(
return concatValues(
q + rA * LUMA_R, rA * LUMA_G, rA * LUMA_B, 0, 0,
gA * LUMA_R, q + gA * LUMA_G, gA * LUMA_B, 0, 0,
bA * LUMA_R, bA * LUMA_G, q + bA * LUMA_B, 0, 0,
Expand Down
11 changes: 6 additions & 5 deletions StarlingFeathers/src/starling/filters/DisplacementMapFilter.as
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ package starling.filters
mComponentY = componentY;
mScaleX = scaleX;
mScaleY = scaleY;
mRepeat = repeat;
this.mapPoint = mapPoint;

super();
Expand Down Expand Up @@ -186,11 +187,11 @@ package starling.filters
// vertex buffer: (containing map texture coordinates)
// The size of input texture and map texture may be different. We need to calculate
// the right values for the texture coordinates at the filter vertices.
var mapX:Number = mMapPoint.x / mapTexture.width;
var mapY:Number = mMapPoint.y / mapTexture.height;
var maxU:Number = textureWidth / mapTexture.nativeWidth;
var maxV:Number = textureHeight / mapTexture.nativeHeight;

var mapX:Number = mMapPoint.x / mapTexture.width;
var mapY:Number = mMapPoint.y / mapTexture.height;
var maxU:Number = textureWidth / (mapTexture.width * scale);
var maxV:Number = textureHeight / (mapTexture.height * scale);

sMapTexCoords[0] = -mapX; sMapTexCoords[1] = -mapY;
sMapTexCoords[2] = -mapX + maxU; sMapTexCoords[3] = -mapY;
Expand Down
2 changes: 1 addition & 1 deletion StarlingFeathers/src/starling/filters/FragmentFilter.as
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ package starling.filters
var stage:Stage = Starling.current.stage;
var scale:Number = Starling.current.contentScaleFactor;
var projMatrix:Matrix = mHelperMatrix;
var projMatrix3D:Matrix3D = mHelperMatrix3D
var projMatrix3D:Matrix3D = mHelperMatrix3D;
var bounds:Rectangle = mHelperRect;
var boundsPot:Rectangle = mHelperRect2;

Expand Down
36 changes: 24 additions & 12 deletions StarlingFeathers/src/starling/text/TextField.as
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ package starling.text
*
* <p>You can set all properties you are used to, like the font name and size, a color, the
* horizontal and vertical alignment, etc. The border property is helpful during development,
* because it lets you see the bounds of the textfield.</p>
* because it lets you see the bounds of the TextField.</p>
*
* <p>There are two types of fonts that can be displayed:</p>
*
Expand All @@ -59,13 +59,20 @@ package starling.text
*
* <ul>
* <li>Windows: <a href="http://www.angelcode.com/products/bmfont">Bitmap Font Generator</a>
* from Angel Code (free). Export the font data as an XML file and the texture as a png
* with white characters on a transparent background (32 bit).</li>
* from Angel Code (free). Export the font data as an XML file and the texture as a png
* with white characters on a transparent background (32 bit).</li>
* <li>Mac OS: <a href="http://glyphdesigner.71squared.com">Glyph Designer</a> from
* 71squared or <a href="http://http://www.bmglyph.com">bmGlyph</a> (both commercial).
* They support Starling natively.</li>
* </ul>
*
*
* <p>When using a bitmap font, the 'color' property is used to tint the font texture. This
* works by multiplying the RGB values of that property with those of the texture's pixel.
* If your font contains just a single color, export it in plain white and change the 'color'
* property to any value you like (it defaults to zero, which means black). If your font
* contains multiple colors, change the 'color' property to <code>Color.WHITE</code> to get
* the intended result.</p>
*
* <strong>Batching of TextFields</strong>
*
* <p>Normally, TextFields will require exactly one draw call. For TrueType fonts, you cannot
Expand Down Expand Up @@ -223,7 +230,7 @@ package starling.text

/** This method is called immediately before the text is rendered. The intent of
* 'formatText' is to be overridden in a subclass, so that you can provide custom
* formatting for the TextField. In the overriden method, call 'setFormat' (either
* formatting for the TextField. In the overridden method, call 'setFormat' (either
* over a range of characters or the complete TextField) to modify the format to
* your needs.
*
Expand Down Expand Up @@ -260,12 +267,13 @@ package starling.text
sNativeTextField.antiAliasType = AntiAliasType.ADVANCED;
sNativeTextField.selectable = false;
sNativeTextField.multiline = true;
sNativeTextField.wordWrap = true;
sNativeTextField.embedFonts = true;
sNativeTextField.filters = mNativeFilters;
sNativeTextField.wordWrap = true;

if (mIsHtmlText) sNativeTextField.htmlText = mText;
else sNativeTextField.text = mText;

sNativeTextField.embedFonts = true;
sNativeTextField.filters = mNativeFilters;

// we try embedded fonts first, non-embedded fonts are just a fallback
if (sNativeTextField.textWidth == 0.0 || sNativeTextField.textHeight == 0.0)
Expand Down Expand Up @@ -331,15 +339,18 @@ package starling.text
{
var size:Number = Number(textField.defaultTextFormat.size);
var maxHeight:int = textField.height - 4;
var maxWidth:int = textField.width - 4;
var maxWidth:int = textField.width - 4;

while (textField.textWidth > maxWidth || textField.textHeight > maxHeight)
{
if (size <= 4) break;

var format:TextFormat = textField.defaultTextFormat;
format.size = size--;
textField.setTextFormat(format);
textField.defaultTextFormat = format;

if (mIsHtmlText) textField.htmlText = mText;
else textField.text = mText;
}
}

Expand Down Expand Up @@ -564,8 +575,9 @@ package starling.text
}
}

/** The color of the text. For bitmap fonts, use <code>Color.WHITE</code> to use the
* original, untinted color. @default black */
/** The color of the text. Note that bitmap fonts should be exported in plain white so
* that tinting works correctly. If your bitmap font contains colors, set this property
* to <code>Color.WHITE</code> to get the desired result. @default black */
public function get color():uint { return mColor; }
public function set color(value:uint):void
{
Expand Down
24 changes: 20 additions & 4 deletions StarlingFeathers/src/starling/textures/AtfData.as
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package starling.textures
private var mWidth:int;
private var mHeight:int;
private var mNumTextures:int;
private var mIsCubeMap:Boolean;
private var mData:ByteArray;

/** Create a new instance by parsing the given byte array. */
Expand All @@ -29,8 +30,9 @@ package starling.textures

if (data[6] == 255) data.position = 12; // new file version
else data.position = 6; // old file version

switch (data.readUnsignedByte())

var format:uint = data.readUnsignedByte();
switch (format & 0x7f)
{
case 0:
case 1: mFormat = Context3DTextureFormat.BGRA; break;
Expand All @@ -45,6 +47,7 @@ package starling.textures
mWidth = Math.pow(2, data.readUnsignedByte());
mHeight = Math.pow(2, data.readUnsignedByte());
mNumTextures = data.readUnsignedByte();
mIsCubeMap = (format & 0x80) != 0;
mData = data;

// version 2 of the new file format contains information about
Expand All @@ -57,7 +60,8 @@ package starling.textures
mNumTextures = emptyMipmaps ? 1 : numTextures;
}
}


/** Checks the first 3 bytes of the data for the 'ATF' signature. */
public static function isAtfData(data:ByteArray):Boolean
{
if (data.length < 3) return false;
Expand All @@ -67,11 +71,23 @@ package starling.textures
return signature == "ATF";
}
}


/** The texture format. @see flash.display3D.textures.Context3DTextureFormat */
public function get format():String { return mFormat; }

/** The width of the texture in pixels. */
public function get width():int { return mWidth; }

/** The height of the texture in pixels. */
public function get height():int { return mHeight; }

/** The number of encoded textures. '1' means that there are no mip maps. */
public function get numTextures():int { return mNumTextures; }

/** Indicates if the ATF data encodes a cube map. Not supported by Starling! */
public function get isCubeMap():Boolean { return mIsCubeMap; }

/** The actual byte data, including header. */
public function get data():ByteArray { return mData; }
}
}
Loading

0 comments on commit e90e69e

Please sign in to comment.