-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- MERGED: optimizations from komelgman (Thanks!)
- ADDED: possibility to add a custom hitTest for nodes - ADDED: new displayobject: Quad2D - A quad with four colors - FIXED: spritesheet distribution in Sprite2DBatch
- Loading branch information
Lars Gerckens
committed
Nov 15, 2011
1 parent
d26772a
commit e2b0d4e
Showing
24 changed files
with
408 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* tests | ||
* @Author: Lars Gerckens (lars@nulldesign.de) | ||
* Date: 15.11.11 19:45 | ||
*/ | ||
package tests { | ||
|
||
import de.nulldesign.nd2d.display.Quad2D; | ||
import de.nulldesign.nd2d.display.Scene2D; | ||
import de.nulldesign.nd2d.display.Sprite2D; | ||
import de.nulldesign.nd2d.materials.Quad2DColorMaterial; | ||
import de.nulldesign.nd2d.utils.ColorUtil; | ||
import de.nulldesign.nd2d.utils.NumberUtil; | ||
|
||
public class QuadMaterialTest extends Scene2D { | ||
|
||
private var colorQuad:Quad2D; | ||
|
||
public function QuadMaterialTest() { | ||
colorQuad = new Quad2D(500.0, 500.0); | ||
addChild(colorQuad); | ||
} | ||
|
||
override protected function step(elapsed:Number):void { | ||
colorQuad.x = stage.stageWidth * 0.5; | ||
colorQuad.y = stage.stageHeight * 0.5; | ||
colorQuad.width = stage.stageWidth; | ||
colorQuad.height = stage.stageHeight; | ||
|
||
colorQuad.topLeftColor = ColorUtil.colorWithAlphaFromColor( | ||
ColorUtil.mixColors(0xFF0000, 0x00FF00, NumberUtil.sin0_1(timeSinceStartInSeconds * 1.2)), | ||
NumberUtil.sin0_1(timeSinceStartInSeconds * 1.3) | ||
); | ||
|
||
colorQuad.topRightColor = ColorUtil.colorWithAlphaFromColor( | ||
ColorUtil.mixColors(0x00FF00, 0x0000FF, NumberUtil.sin0_1(timeSinceStartInSeconds * 1.4)), | ||
NumberUtil.sin0_1(timeSinceStartInSeconds * 1.5) | ||
); | ||
colorQuad.bottomLeftColor = ColorUtil.colorWithAlphaFromColor( | ||
ColorUtil.mixColors(0xFF0000, 0x00FF00, NumberUtil.sin0_1(timeSinceStartInSeconds * 1.6)), | ||
NumberUtil.sin0_1(timeSinceStartInSeconds * 1.7) | ||
); | ||
|
||
colorQuad.bottomRightColor = ColorUtil.colorWithAlphaFromColor( | ||
ColorUtil.mixColors(0x00FF00, 0x0000FF, NumberUtil.sin0_1(timeSinceStartInSeconds * 1.8)), | ||
NumberUtil.sin0_1(timeSinceStartInSeconds * 1.9) | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* de.nulldesign.nd2d.display | ||
* @Author: Lars Gerckens (lars@nulldesign.de) | ||
* Date: 15.11.11 19:49 | ||
*/ | ||
package de.nulldesign.nd2d.display { | ||
|
||
import de.nulldesign.nd2d.geom.Face; | ||
import de.nulldesign.nd2d.geom.Vertex; | ||
import de.nulldesign.nd2d.materials.BlendModePresets; | ||
import de.nulldesign.nd2d.materials.Quad2DColorMaterial; | ||
import de.nulldesign.nd2d.utils.TextureHelper; | ||
|
||
import flash.display3D.Context3D; | ||
|
||
public class Quad2D extends Node2D { | ||
|
||
protected var faceList:Vector.<Face>; | ||
protected var material:Quad2DColorMaterial; | ||
|
||
public function get topLeftColor():uint { | ||
return faceList[0].v1.color; | ||
} | ||
|
||
public function set topLeftColor(value:uint):void { | ||
var v:Vertex = faceList[0].v1; | ||
v.color = value; | ||
material.modifyColorInBuffer(0, v.r, v.g, v.b, v.a); | ||
} | ||
|
||
public function get topRightColor():uint { | ||
return faceList[0].v2.color; | ||
} | ||
|
||
public function set topRightColor(value:uint):void { | ||
var v:Vertex = faceList[0].v2; | ||
v.color = value; | ||
material.modifyColorInBuffer(1, v.r, v.g, v.b, v.a); | ||
} | ||
|
||
public function get bottomRightColor():uint { | ||
return faceList[0].v3.color; | ||
} | ||
|
||
public function set bottomRightColor(value:uint):void { | ||
var v:Vertex = faceList[0].v3; | ||
v.color = value; | ||
material.modifyColorInBuffer(2, v.r, v.g, v.b, v.a); | ||
} | ||
|
||
public function get bottomLeftColor():uint { | ||
return faceList[1].v3.color; | ||
} | ||
|
||
public function set bottomLeftColor(value:uint):void { | ||
var v:Vertex = faceList[1].v3; | ||
v.color = value; | ||
material.modifyColorInBuffer(3, v.r, v.g, v.b, v.a); | ||
} | ||
|
||
public function Quad2D(pWidth:Number, pHeight:Number) { | ||
|
||
_width = pWidth; | ||
_height = pHeight; | ||
|
||
faceList = TextureHelper.generateQuadFromDimensions(pWidth, pHeight); | ||
material = new Quad2DColorMaterial(); | ||
|
||
topLeftColor = 0xFFFF0000; | ||
topRightColor = 0xFF00FF00; | ||
bottomRightColor = 0xFF0000FF; | ||
bottomLeftColor = 0xFFFFFF00; | ||
|
||
blendMode = BlendModePresets.NORMAL_NO_PREMULTIPLIED_ALPHA; | ||
} | ||
|
||
override public function get numTris():uint { | ||
return faceList.length; | ||
} | ||
|
||
override public function get drawCalls():uint { | ||
return material.drawCalls; | ||
} | ||
|
||
override public function handleDeviceLoss():void { | ||
super.handleDeviceLoss(); | ||
if(material) | ||
material.handleDeviceLoss(); | ||
} | ||
|
||
override protected function draw(context:Context3D, camera:Camera2D):void { | ||
|
||
material.blendMode = blendMode; | ||
material.modelMatrix = worldModelMatrix; | ||
material.viewProjectionMatrix = camera.getViewProjectionMatrix(false); | ||
material.render(context, faceList, 0, faceList.length); | ||
} | ||
|
||
override public function dispose():void { | ||
if(material) { | ||
material.dispose(); | ||
material = null; | ||
} | ||
super.dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.