From d1e28efb87b4ee0e5316ada64b415a4356cede9e Mon Sep 17 00:00:00 2001 From: fanflash Date: Wed, 30 Oct 2013 15:13:21 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=90=8D=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- src/org/axgl/AxButton.as | 2 +- src/org/axgl/resource/AxResource.as | 10 +++++----- src/org/axgl/text/AxText.as | 2 +- src/org/axgl/util/debug/AxDebugConsole.as | 2 +- src/org/axgl/util/debug/AxDebugger.as | 12 ++++++------ 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 298140c..b5d58ee 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ docs .settings .actionScriptProperties .project -.git \ No newline at end of file +.git +/bin/Axel.swc diff --git a/src/org/axgl/AxButton.as b/src/org/axgl/AxButton.as index 8449235..29ef572 100644 --- a/src/org/axgl/AxButton.as +++ b/src/org/axgl/AxButton.as @@ -72,7 +72,7 @@ package org.axgl { */ public function text(str:String, font:AxFont = null, verticalOffset:uint = 10, horizontalOffset:uint = 0):AxButton { if (font == null) { - font = AxResource.font; + font = AxResource.FONT; } labelY = verticalOffset; diff --git a/src/org/axgl/resource/AxResource.as b/src/org/axgl/resource/AxResource.as index 45674d8..8b7ce07 100644 --- a/src/org/axgl/resource/AxResource.as +++ b/src/org/axgl/resource/AxResource.as @@ -6,17 +6,17 @@ package org.axgl.resource { */ public class AxResource { /* The small axel icon */ - [Embed(source = "icon.png")] public static const ICON:Class; + [Embed(source = "./icon.png")] public static const ICON:Class; /* Default AxButton background */ - [Embed(source = "button.png")] public static const BUTTON:Class; + [Embed(source = "./button.png")] public static const BUTTON:Class; /* Build in Axel font */ - [Embed(source = "font.png")] public static const FONT_BITMAP:Class; - public static var font:AxFont; + [Embed(source = "./font.png")] public static const FONT_BITMAP:Class; + public static var FONT:AxFont; public static function initialize():void { - font = AxFont.fromBitmap(FONT_BITMAP, 1, 0); + FONT = AxFont.fromBitmap(FONT_BITMAP, 1, 0); } } } \ No newline at end of file diff --git a/src/org/axgl/text/AxText.as b/src/org/axgl/text/AxText.as index 6c67db7..846fa45 100644 --- a/src/org/axgl/text/AxText.as +++ b/src/org/axgl/text/AxText.as @@ -54,7 +54,7 @@ package org.axgl.text { super(x, y, VERTEX_SHADER, FRAGMENT_SHADER, 8); this._text = text; - this.font = font ? font : AxResource.font; + this.font = font ? font : AxResource.FONT; this.width = this.requestedWidth = width; this.align = align; diff --git a/src/org/axgl/util/debug/AxDebugConsole.as b/src/org/axgl/util/debug/AxDebugConsole.as index 73b5f81..a28f385 100644 --- a/src/org/axgl/util/debug/AxDebugConsole.as +++ b/src/org/axgl/util/debug/AxDebugConsole.as @@ -29,7 +29,7 @@ package org.axgl.util.debug { public function AxDebugConsole() { this.add(background = new AxSprite(0, 0)); - this.add(text = new AxText(5, 5, AxResource.font, "", Ax.viewWidth - 20)); + this.add(text = new AxText(5, 5, AxResource.FONT, "", Ax.viewWidth - 20)); background.scroll.x = background.scroll.y = 0; text.scroll.x = text.scroll.y = 0; background.zooms = text.zooms = false; diff --git a/src/org/axgl/util/debug/AxDebugger.as b/src/org/axgl/util/debug/AxDebugger.as index 6184e22..a54fa30 100644 --- a/src/org/axgl/util/debug/AxDebugger.as +++ b/src/org/axgl/util/debug/AxDebugger.as @@ -49,32 +49,32 @@ package org.axgl.util.debug { var version:Array = Ax.LIBRARY_VERSION.split("."); var debugMode:String = Ax.debug ? "@[255,90,90]Debug" : "@[200,200,200]Release"; - libraryText = new AxText(4, 3, AxResource.font, Ax.LIBRARY_NAME + " @[160,160,160]Version @[150,150,255]" + version[0] + "@[10,255,255].@[180,180,255]" + version[1] + "@[255,255,255].@[210,210,255]" + version[2] + " " + debugMode); + libraryText = new AxText(4, 3, AxResource.FONT, Ax.LIBRARY_NAME + " @[160,160,160]Version @[150,150,255]" + version[0] + "@[10,255,255].@[180,180,255]" + version[1] + "@[255,255,255].@[210,210,255]" + version[2] + " " + debugMode); libraryText.scroll.x = libraryText.scroll.y = 0; libraryText.zooms = libraryText.countTris = false; this.add(libraryText); - fpsText = new AxText(4, Ax.height - HEIGHT + 3, AxResource.font, "FPS: 0/0"); + fpsText = new AxText(4, Ax.height - HEIGHT + 3, AxResource.FONT, "FPS: 0/0"); fpsText.scroll.x = fpsText.scroll.y = 0; fpsText.zooms = fpsText.countTris = false; this.add(fpsText); - memoryText = new AxText(70, Ax.height - HEIGHT + 3, AxResource.font, "Memory: 0MB"); + memoryText = new AxText(70, Ax.height - HEIGHT + 3, AxResource.FONT, "Memory: 0MB"); memoryText.scroll.x = memoryText.scroll.y = 0; memoryText.zooms = memoryText.countTris = false; this.add(memoryText); - modeText = new AxText(0, 3, AxResource.font, "---", Ax.width - 3, "right"); + modeText = new AxText(0, 3, AxResource.FONT, "---", Ax.width - 3, "right"); modeText.scroll.x = modeText.scroll.y = 0; modeText.zooms = modeText.countTris = false; this.add(modeText); - timeText = new AxText(0, Ax.height - HEIGHT + 3, AxResource.font, "---", Ax.width - 5, "right"); + timeText = new AxText(0, Ax.height - HEIGHT + 3, AxResource.FONT, "---", Ax.width - 5, "right"); timeText.scroll.x = timeText.scroll.y = 0; timeText.zooms = timeText.countTris = false; this.add(timeText); - titleText = new AxText(0, 3, AxResource.font, "", Ax.width, "center"); + titleText = new AxText(0, 3, AxResource.FONT, "", Ax.width, "center"); titleText.scroll.x = titleText.scroll.y = 0; titleText.zooms = titleText.countTris = false; this.add(titleText); From 61bfd15ac4eff6595650ff1375e22fb959e2278e Mon Sep 17 00:00:00 2001 From: fanflash Date: Thu, 31 Oct 2013 00:47:58 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=90=8D=E9=94=99=E8=AF=AF=20fix=20value=20bug.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- src/org/axgl/AxButton.as | 2 +- src/org/axgl/resource/AxResource.as | 4 ++-- src/org/axgl/text/AxText.as | 2 +- src/org/axgl/util/debug/AxDebugConsole.as | 2 +- src/org/axgl/util/debug/AxDebugger.as | 12 ++++++------ 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 298140c..763d2ba 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ docs .settings .actionScriptProperties .project -.git \ No newline at end of file +.git +/.flexLibProperties +/bin/Axel.swc diff --git a/src/org/axgl/AxButton.as b/src/org/axgl/AxButton.as index 8449235..29ef572 100644 --- a/src/org/axgl/AxButton.as +++ b/src/org/axgl/AxButton.as @@ -72,7 +72,7 @@ package org.axgl { */ public function text(str:String, font:AxFont = null, verticalOffset:uint = 10, horizontalOffset:uint = 0):AxButton { if (font == null) { - font = AxResource.font; + font = AxResource.FONT; } labelY = verticalOffset; diff --git a/src/org/axgl/resource/AxResource.as b/src/org/axgl/resource/AxResource.as index 45674d8..6a0d9d8 100644 --- a/src/org/axgl/resource/AxResource.as +++ b/src/org/axgl/resource/AxResource.as @@ -13,10 +13,10 @@ package org.axgl.resource { /* Build in Axel font */ [Embed(source = "font.png")] public static const FONT_BITMAP:Class; - public static var font:AxFont; + public static var FONT:AxFont; public static function initialize():void { - font = AxFont.fromBitmap(FONT_BITMAP, 1, 0); + FONT = AxFont.fromBitmap(FONT_BITMAP, 1, 0); } } } \ No newline at end of file diff --git a/src/org/axgl/text/AxText.as b/src/org/axgl/text/AxText.as index 6c67db7..846fa45 100644 --- a/src/org/axgl/text/AxText.as +++ b/src/org/axgl/text/AxText.as @@ -54,7 +54,7 @@ package org.axgl.text { super(x, y, VERTEX_SHADER, FRAGMENT_SHADER, 8); this._text = text; - this.font = font ? font : AxResource.font; + this.font = font ? font : AxResource.FONT; this.width = this.requestedWidth = width; this.align = align; diff --git a/src/org/axgl/util/debug/AxDebugConsole.as b/src/org/axgl/util/debug/AxDebugConsole.as index 73b5f81..a28f385 100644 --- a/src/org/axgl/util/debug/AxDebugConsole.as +++ b/src/org/axgl/util/debug/AxDebugConsole.as @@ -29,7 +29,7 @@ package org.axgl.util.debug { public function AxDebugConsole() { this.add(background = new AxSprite(0, 0)); - this.add(text = new AxText(5, 5, AxResource.font, "", Ax.viewWidth - 20)); + this.add(text = new AxText(5, 5, AxResource.FONT, "", Ax.viewWidth - 20)); background.scroll.x = background.scroll.y = 0; text.scroll.x = text.scroll.y = 0; background.zooms = text.zooms = false; diff --git a/src/org/axgl/util/debug/AxDebugger.as b/src/org/axgl/util/debug/AxDebugger.as index 6184e22..a54fa30 100644 --- a/src/org/axgl/util/debug/AxDebugger.as +++ b/src/org/axgl/util/debug/AxDebugger.as @@ -49,32 +49,32 @@ package org.axgl.util.debug { var version:Array = Ax.LIBRARY_VERSION.split("."); var debugMode:String = Ax.debug ? "@[255,90,90]Debug" : "@[200,200,200]Release"; - libraryText = new AxText(4, 3, AxResource.font, Ax.LIBRARY_NAME + " @[160,160,160]Version @[150,150,255]" + version[0] + "@[10,255,255].@[180,180,255]" + version[1] + "@[255,255,255].@[210,210,255]" + version[2] + " " + debugMode); + libraryText = new AxText(4, 3, AxResource.FONT, Ax.LIBRARY_NAME + " @[160,160,160]Version @[150,150,255]" + version[0] + "@[10,255,255].@[180,180,255]" + version[1] + "@[255,255,255].@[210,210,255]" + version[2] + " " + debugMode); libraryText.scroll.x = libraryText.scroll.y = 0; libraryText.zooms = libraryText.countTris = false; this.add(libraryText); - fpsText = new AxText(4, Ax.height - HEIGHT + 3, AxResource.font, "FPS: 0/0"); + fpsText = new AxText(4, Ax.height - HEIGHT + 3, AxResource.FONT, "FPS: 0/0"); fpsText.scroll.x = fpsText.scroll.y = 0; fpsText.zooms = fpsText.countTris = false; this.add(fpsText); - memoryText = new AxText(70, Ax.height - HEIGHT + 3, AxResource.font, "Memory: 0MB"); + memoryText = new AxText(70, Ax.height - HEIGHT + 3, AxResource.FONT, "Memory: 0MB"); memoryText.scroll.x = memoryText.scroll.y = 0; memoryText.zooms = memoryText.countTris = false; this.add(memoryText); - modeText = new AxText(0, 3, AxResource.font, "---", Ax.width - 3, "right"); + modeText = new AxText(0, 3, AxResource.FONT, "---", Ax.width - 3, "right"); modeText.scroll.x = modeText.scroll.y = 0; modeText.zooms = modeText.countTris = false; this.add(modeText); - timeText = new AxText(0, Ax.height - HEIGHT + 3, AxResource.font, "---", Ax.width - 5, "right"); + timeText = new AxText(0, Ax.height - HEIGHT + 3, AxResource.FONT, "---", Ax.width - 5, "right"); timeText.scroll.x = timeText.scroll.y = 0; timeText.zooms = timeText.countTris = false; this.add(timeText); - titleText = new AxText(0, 3, AxResource.font, "", Ax.width, "center"); + titleText = new AxText(0, 3, AxResource.FONT, "", Ax.width, "center"); titleText.scroll.x = titleText.scroll.y = 0; titleText.zooms = titleText.countTris = false; this.add(titleText); From 0f410ebdce878c9902203a757378158f8068d5cc Mon Sep 17 00:00:00 2001 From: fanflash Date: Thu, 31 Oct 2013 12:25:42 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=B8=BAAxSprite=E5=A2=9E=E5=8A=A0addAnima?= =?UTF-8?q?tionByFristFrame=E6=96=B9=E6=B3=95=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit in AxSprite added function addAnimationByFristFrame --- src/org/axgl/AxSprite.as | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/org/axgl/AxSprite.as b/src/org/axgl/AxSprite.as index b01967b..0795440 100644 --- a/src/org/axgl/AxSprite.as +++ b/src/org/axgl/AxSprite.as @@ -260,6 +260,31 @@ package org.axgl { animations[name] = new AxAnimation(name, frames, framerate < 1 ? 15 : framerate, looped, callback); return this; } + + /** + * Adds a new animation to this sprite. The name of the animation is what you will use to access it via the animate + * function. The firstFrame is first frame ID. The frameNum is total number of the frame. Framerate is + * how fast the animation will play; it indicates how many frames will be played per second. If you have a 5 frame animation with a + * framerate of 10, it will play the animation twice per second. The looped parameter indicates whether or not this + * animation should stop at the end of the animation, or if it should loop repeatedly. + * + * @param name The name of the animation. + * @param firstFrame The firstFrame represents the first frame ID. + * @param frameNum The frameNum represents the total number of frames. + * @param framerate The framerate at which the animation should play. + * @param looped Whether or not the animation should loop. + * + * @return The sprite instance. + */ + public function addAnimationByFristFrame(name:String, firstFrame:uint, frameNum:uint = 1, framerate:uint = 15, looped:Boolean = true, callback:Function = null):AxSprite{ + + var frames:Array = []; + var endFrame:int = firstFrame + frameNum; + for(var i:int = firstFrame; i < endFrame; i++){ + frames.push(i); + } + return this.addAnimation(name,frames,framerate,looped,callback); + } /** * Tells this sprite to immediately start playing the animation that you passed. If that animation is already playing, @@ -300,15 +325,20 @@ package org.axgl { */ private function calculateFrame():void { if (animation != null) { + + //cache value; + var nextFrame:uint = frame + 1; + var frameLen:uint = animation.frames.length; + animationTimer += Ax.dt; while (animationTimer >= animationDelay) { animationTimer -= animationDelay; - if (frame + 1 < animation.frames.length || animation.looped) { - frame = (frame + 1) % animation.frames.length; + if (nextFrame < frameLen || animation.looped) { + frame = nextFrame % frameLen; } uvOffset[0] = (animation.frames[frame] % framesPerRow) * quad.uvWidth; uvOffset[1] = Math.floor(animation.frames[frame] / framesPerRow) * quad.uvHeight; - if (frame + 1 == animation.frames.length && animation.callback != null) { + if (nextFrame == frameLen && animation.callback != null) { animation.callback(); } }