Permalink
Browse files

- FIXED: GUI layer rendering

- ADDED: animation end event
- ADDED: pixel perfect hittest for Sprite2D
  • Loading branch information...
1 parent 8856ce9 commit 3981cdbaab1e6ed3c504b17a9fbe9035bfc463f6 Lars Gerckens committed Jan 13, 2012
Showing with 25 additions and 14 deletions.
  1. +2 −14 examples/Main.as
  2. +1 −0 examples/tests/SpriteHierarchyTest.as
  3. +22 −0 src/de/nulldesign/nd2d/display/Sprite2D.as
View
@@ -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
@@ -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;
@@ -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();

0 comments on commit 3981cdb

Please sign in to comment.