Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 11 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jan 13, 2012
@lrrrs - FIXED: GUI layer rendering
- ADDED: animation end event
5547dac
@lrrrs - FIXED: GUI layer rendering
- ADDED: animation end event
7f8ead6
@lrrrs Merge branch 'master' of github.com:nulldesign/nd2d 8856ce9
@lrrrs - FIXED: GUI layer rendering
- ADDED: animation end event
- ADDED: pixel perfect hittest for Sprite2D
3981cdb
View
5 README.md
@@ -45,6 +45,11 @@ Important links:
# Changelog:
+2012-01-13
+
+- FIXED: GUI layer rendering
+- ADDED: animation end event
+
2011-12-07
- ADDED: getChildByTag and tag property for Node2D
View
3  TODO.txt
@@ -1,4 +1,3 @@
-- blurmaterial
- Zoë: A SWF animation exporter for the EaselJS library. ? more TextureAtlas tools?
- multiple worlds test
- camera zoom example for independent resolutions
@@ -14,4 +13,6 @@ What I don't like about the spritesheets is:
About Sprite2DBatch: only addChildAt/removeChildAt are implemented and I'm not sure why addChild/removeChild aren't - maybe there's a hidden reason? Also invalidation in the *At methods seem a bit aggressive.
getChildByTag()
+- events for end / start of animations?
- camera pivot? rotation point?
+- TextureAtlas clone?? for batches, better solution
View
16 examples/Main.as
@@ -75,7 +75,7 @@ package {
import tests.TextureAndRotationOptionsTest;
import tests.TextureAtlasTest;
import tests.TextureRendererTest;
- import tests.Transform3DTest;
+ import tests.Transform3DTest;
[SWF(width="1000", height="550", frameRate="60", backgroundColor="#000000")]
public class Main extends World2D {
@@ -144,25 +144,13 @@ package {
stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
start();
-
- // test buttons
- /*
- var b:PushButton;
- b = new PushButton(this, 380, 0, "next", buttonClicked);
- b.tag = 0;
- */
-
- addChild(new PushButton(this, 220, 0, "next", nextButtonClick));
+ //addChild(new PushButton(this, 220, 0, "next", nextButtonClick));
}
private function nextButtonClick(e:MouseEvent):void {
nextDemo();
}
- private function buttonClicked(e:MouseEvent):void {
- nextDemo();
- }
-
private function keyUp(e:KeyboardEvent):void {
if(e.keyCode == Keyboard.D) {
// simulate device loss
View
12 examples/tests/CameraTest.as
@@ -33,11 +33,13 @@ package tests {
import de.nulldesign.nd2d.display.Node2D;
import de.nulldesign.nd2d.display.Scene2D;
import de.nulldesign.nd2d.display.Sprite2D;
+ import de.nulldesign.nd2d.display.TextField2D;
import de.nulldesign.nd2d.materials.texture.Texture2D;
import de.nulldesign.nd2d.utils.NumberUtil;
import flash.events.Event;
import flash.events.MouseEvent;
+ import flash.text.TextFormatAlign;
public class CameraTest extends Scene2D {
@@ -83,6 +85,16 @@ package tests {
s.mouseEnabled = true;
s.addEventListener(MouseEvent.CLICK, guiLayerItemClick);
sceneGUILayer.addChild(s);
+
+ var txt:TextField2D = new TextField2D();
+ txt.font = "Helvetica";
+ txt.textColor = 0xFF9900;
+ txt.size = 30.0;
+ txt.align = TextFormatAlign.LEFT;
+ txt.text = "GUI Layer";
+ txt.x = 120.0;
+ txt.y = stage.stageHeight - s.height * 0.5;
+ sceneGUILayer.addChild(txt);
}
private function guiLayerItemClick(e:MouseEvent):void {
View
1  examples/tests/SpriteHierarchyTest.as
@@ -85,6 +85,7 @@ package tests {
s3 = new Sprite2D(tex2);
s3.setSpriteSheet(sheet);
s3.mouseEnabled = true;
+ s3.usePixelPerfectHitTest = true;
s3.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
s3.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
s3.scaleX = s3.scaleY = 4.0;
View
5 src/de/nulldesign/nd2d/display/Scene2D.as
@@ -75,6 +75,11 @@ package de.nulldesign.nd2d.display {
sceneGUILayer.handleDeviceLoss();
}
+ override internal function stepNode(elapsed:Number, timeSinceStartInSeconds:Number):void {
+ super.stepNode(elapsed, timeSinceStartInSeconds);
+ sceneGUILayer.stepNode(elapsed, timeSinceStartInSeconds);
+ }
+
override internal function drawNode(context:Context3D, camera:Camera2D, parentMatrixChanged:Boolean, statsObject:StatsObject):void {
for each(var child:Node2D in children) {
View
22 src/de/nulldesign/nd2d/display/Sprite2D.as
@@ -40,6 +40,7 @@ package de.nulldesign.nd2d.display {
import flash.display.BitmapData;
import flash.display3D.Context3D;
+ import flash.geom.Rectangle;
/**
* <p>2D sprite class</p>
@@ -55,6 +56,8 @@ package de.nulldesign.nd2d.display {
public var spriteSheet:ASpriteSheetBase;
public var material:Sprite2DMaterial;
+ public var usePixelPerfectHitTest:Boolean = false;
+
public var isBatchNode:Boolean = false;
/**
@@ -199,6 +202,25 @@ package de.nulldesign.nd2d.display {
material.render(context, faceList, 0, faceList.length);
}
+ override protected function hitTest():Boolean {
+
+ if(usePixelPerfectHitTest && texture.bitmap) {
+
+ var xCoord:Number = _mouseX + (_width >> 1);
+ var yCoord:Number = _mouseY + (_height >> 1);
+
+ if(spriteSheet) {
+ var rect:Rectangle = spriteSheet.getDimensionForFrame();
+ xCoord += rect.x;
+ yCoord += rect.y;
+ }
+
+ return super.hitTest() && (texture.bitmap.getPixel32(xCoord, yCoord) >> 24 & 0xFF) > 0;
+ }
+
+ return super.hitTest();
+ }
+
override public function dispose():void {
if(material) {
material.dispose();
View
18 src/de/nulldesign/nd2d/events/SpriteSheetAnimationEvent.as
@@ -0,0 +1,18 @@
+/**
+ * de.nulldesign.nd2d.events
+ * @Author: Lars Gerckens (lars@nulldesign.de)
+ * Date: 10.01.12 23:52
+ */
+package de.nulldesign.nd2d.events {
+
+ import flash.events.Event;
+
+ public class SpriteSheetAnimationEvent extends Event {
+
+ public static const ANIMATION_FINISHED:String = "animationFinished";
+
+ public function SpriteSheetAnimationEvent(type:String) {
+ super(type);
+ }
+ }
+}
View
196 src/de/nulldesign/nd2d/materials/texture/ASpriteSheetBase.as
@@ -30,144 +30,156 @@
package de.nulldesign.nd2d.materials.texture {
+ import de.nulldesign.nd2d.events.SpriteSheetAnimationEvent;
import de.nulldesign.nd2d.materials.texture.SpriteSheetAnimation;
+ import flash.events.EventDispatcher;
+
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.utils.Dictionary;
- public class ASpriteSheetBase {
+ public class ASpriteSheetBase extends EventDispatcher {
- protected var frames:Vector.<Rectangle> = new Vector.<Rectangle>();
- protected var offsets:Vector.<Point> = new Vector.<Point>();
- protected var sourceSizes:Vector.<Point> = new Vector.<Point>();
+ protected var frames:Vector.<Rectangle> = new Vector.<Rectangle>();
+ protected var offsets:Vector.<Point> = new Vector.<Point>();
+ protected var sourceSizes:Vector.<Point> = new Vector.<Point>();
protected var sourceColorRects:Vector.<Rectangle> = new Vector.<Rectangle>();
- protected var frameNameToIndex:Dictionary = new Dictionary();
- protected var uvRects:Vector.<Rectangle>;
- protected var spritesPackedWithoutSpace:Boolean;
+ protected var frameNameToIndex:Dictionary = new Dictionary();
+ protected var uvRects:Vector.<Rectangle>;
+ protected var spritesPackedWithoutSpace:Boolean;
+
+ protected var ctime:Number = 0.0;
+ protected var otime:Number = 0.0;
+ protected var interp:Number = 0.0;
- protected var ctime:Number = 0.0;
- protected var otime:Number = 0.0;
- protected var interp:Number = 0.0;
+ protected var triggerEventOnLastFrame:Boolean = false;
- protected var frameIdx:uint = 0;
+ protected var frameIdx:uint = 0;
- protected var activeAnimation:SpriteSheetAnimation;
- protected var animationMap:Dictionary = new Dictionary();
+ protected var activeAnimation:SpriteSheetAnimation;
+ protected var animationMap:Dictionary = new Dictionary();
- public var frameUpdated:Boolean = true;
+ public var frameUpdated:Boolean = true;
- protected var fps:uint;
+ protected var fps:uint;
- protected var _spriteWidth:Number;
- protected var _spriteHeight:Number;
- protected var _sheetWidth:Number;
- protected var _sheetHeight:Number;
+ protected var _spriteWidth:Number;
+ protected var _spriteHeight:Number;
+ protected var _sheetWidth:Number;
+ protected var _sheetHeight:Number;
- public function get spriteWidth():Number {
- return _spriteWidth;
- }
+ public function get spriteWidth():Number {
+ return _spriteWidth;
+ }
- public function get spriteHeight():Number {
- return _spriteHeight;
- }
+ public function get spriteHeight():Number {
+ return _spriteHeight;
+ }
- protected var _frame:uint = int.MAX_VALUE;
+ protected var _frame:uint = int.MAX_VALUE;
- public function get frame():uint {
- return _frame;
- }
+ public function get frame():uint {
+ return _frame;
+ }
- public function set frame(value:uint):void {
- if(frame != value) {
- _frame = value;
- frameUpdated = true;
+ public function set frame(value:uint):void {
+ if(frame != value) {
+ _frame = value;
+ frameUpdated = true;
- if(frames.length - 1 >= _frame) {
- _spriteWidth = frames[_frame].width;
- _spriteHeight = frames[_frame].height;
- }
- }
- }
+ if(frames.length - 1 >= _frame) {
+ _spriteWidth = frames[_frame].width;
+ _spriteHeight = frames[_frame].height;
+ }
+ }
+ }
- public function ASpriteSheetBase() {
- }
+ public function ASpriteSheetBase() {
+ }
- public function update(t:Number):void {
+ public function update(t:Number):void {
- if(!activeAnimation) return;
+ if(!activeAnimation) return;
- ctime = t;
+ ctime = t;
- // Update the timer part, to get time based animation
- interp += fps * (ctime - otime);
- if(interp >= 1.0) {
- frameIdx++;
- interp = 0;
- }
+ // Update the timer part, to get time based animation
+ interp += fps * (ctime - otime);
+ if(interp >= 1.0) {
+ frameIdx++;
+ interp = 0;
+ }
- if(activeAnimation.loop) {
- frameIdx = frameIdx % activeAnimation.numFrames;
- } else {
- frameIdx = Math.min(frameIdx, activeAnimation.numFrames - 1);
- }
+ if(activeAnimation.loop) {
+ frameIdx = frameIdx % activeAnimation.numFrames;
+ } else {
+ frameIdx = Math.min(frameIdx, activeAnimation.numFrames - 1);
+ }
- frame = activeAnimation.frames[frameIdx];
+ frame = activeAnimation.frames[frameIdx];
- otime = ctime;
- }
+ otime = ctime;
- public function playAnimation(name:String, startIdx:uint = 0, restart:Boolean = false):void {
- if(restart || activeAnimation != animationMap[name]) {
- frameIdx = startIdx;
- activeAnimation = animationMap[name];
- }
- }
+ if(triggerEventOnLastFrame && frameIdx == activeAnimation.numFrames - 1) {
+ dispatchEvent(new SpriteSheetAnimationEvent(SpriteSheetAnimationEvent.ANIMATION_FINISHED));
+ }
+ }
+
+ public function playAnimation(name:String, startIdx:uint = 0, restart:Boolean = false, triggerEventOnLastFrame:Boolean = false):void {
+
+ this.triggerEventOnLastFrame = triggerEventOnLastFrame;
+
+ if(restart || activeAnimation != animationMap[name]) {
+ frameIdx = startIdx;
+ activeAnimation = animationMap[name];
+ }
+ }
public function addAnimation(name:String, keyFrames:Array, loop:Boolean):void {
}
- public function clone():ASpriteSheetBase {
- return null;
- }
+ public function clone():ASpriteSheetBase {
+ return null;
+ }
- public function getOffsetForFrame():Point {
- return offsets[frame];
- }
+ public function getOffsetForFrame():Point {
+ return offsets[frame];
+ }
public function getDimensionForFrame():Rectangle {
return frames[frame];
}
- public function getUVRectForFrame(textureWidth:Number, textureHeight:Number):Rectangle {
+ public function getUVRectForFrame(textureWidth:Number, textureHeight:Number):Rectangle {
- if(uvRects[frame]) {
- return uvRects[frame];
- }
+ if(uvRects[frame]) {
+ return uvRects[frame];
+ }
- var rect:Rectangle = frames[frame].clone();
- var texturePixelOffset:Point = new Point((textureWidth - _sheetWidth) / 2.0, (textureHeight - _sheetHeight) / 2.0);
+ var rect:Rectangle = frames[frame].clone();
+ var texturePixelOffset:Point = new Point((textureWidth - _sheetWidth) / 2.0, (textureHeight - _sheetHeight) / 2.0);
- rect.x += texturePixelOffset.x;
- rect.y += texturePixelOffset.y;
+ rect.x += texturePixelOffset.x;
+ rect.y += texturePixelOffset.y;
- if(spritesPackedWithoutSpace) {
- rect.x += 0.5;
- rect.y += 0.5;
+ if(spritesPackedWithoutSpace) {
+ rect.x += 0.5;
+ rect.y += 0.5;
- rect.width -= 1.0;
- rect.height -= 1.0;
- }
+ rect.width -= 1.0;
+ rect.height -= 1.0;
+ }
- rect.x /= textureWidth;
- rect.y /= textureHeight;
- rect.width /= textureWidth;
- rect.height /= textureHeight;
+ rect.x /= textureWidth;
+ rect.y /= textureHeight;
+ rect.width /= textureWidth;
+ rect.height /= textureHeight;
- uvRects[frame] = rect;
+ uvRects[frame] = rect;
- return rect;
- }
- }
+ return rect;
+ }
+ }
}
View
2  src/de/nulldesign/nd2d/materials/texture/SpriteSheet.as
@@ -30,8 +30,6 @@
package de.nulldesign.nd2d.materials.texture {
- import de.nulldesign.nd2d.materials.*;
-
import flash.geom.Point;
import flash.geom.Rectangle;
View
2  src/de/nulldesign/nd2d/materials/texture/TextureAtlas.as
@@ -30,8 +30,6 @@
package de.nulldesign.nd2d.materials.texture {
- import de.nulldesign.nd2d.materials.*;
-
import flash.geom.Point;
import flash.geom.Rectangle;

No commit comments for this range

Something went wrong with that request. Please try again.