Permalink
Browse files

Merge branch 'master' of github.com:nulldesign/nd2d

  • Loading branch information...
2 parents 7f8ead6 + 450e888 commit 8856ce985f0d555c569120aee59c7306136c0e50 Lars Gerckens committed Jan 13, 2012
View
@@ -31,10 +31,12 @@
package {
import avmplus.getQualifiedClassName;
-
+
+ import com.bit101.components.PushButton;
+
import de.nulldesign.nd2d.display.Scene2D;
import de.nulldesign.nd2d.display.World2D;
-
+
import flash.display.StageAlign;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
@@ -45,13 +47,12 @@ package {
import flash.text.TextField;
import flash.text.TextFormat;
import flash.ui.Keyboard;
-
+
import net.hires.debug.Stats;
-
+
import tests.BatchTest;
import tests.BlurTest;
import tests.CameraTest;
- import tests.QuadMaterialTest;
import tests.ColorTransformTest;
import tests.Font2DTest;
import tests.Grid2DTest;
@@ -61,6 +62,7 @@ package {
import tests.ParticleExplorer;
import tests.ParticleSystemTest;
import tests.PostProcessingTest;
+ import tests.QuadMaterialTest;
import tests.SideScrollerTest;
import tests.SpeedTest;
import tests.Sprite2DCloudParticles;
@@ -70,12 +72,12 @@ package {
import tests.SpriteTest;
import tests.StarFieldTest;
import tests.TextFieldTest;
+ import tests.TextureAndRotationOptionsTest;
import tests.TextureAtlasTest;
import tests.TextureRendererTest;
- import tests.TextureAndRotationOptionsTest;
- import tests.Transform3DTest;
+ import tests.Transform3DTest;
- //[SWF(width="1000", height="550", frameRate="60", backgroundColor="#000000")]
+ [SWF(width="1000", height="550", frameRate="60", backgroundColor="#000000")]
public class Main extends World2D {
private var scenes:Vector.<Scene2D> = new Vector.<Scene2D>();
@@ -137,7 +139,7 @@ package {
stageResize(null);
activeSceneIdx = scenes.length - 1;
- nextBtnClick();
+ nextDemo();
stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
@@ -149,24 +151,30 @@ package {
b = new PushButton(this, 380, 0, "next", buttonClicked);
b.tag = 0;
*/
+
+ addChild(new PushButton(this, 220, 0, "next", nextButtonClick));
+ }
+
+ private function nextButtonClick(e:MouseEvent):void {
+ nextDemo();
}
private function buttonClicked(e:MouseEvent):void {
- nextBtnClick();
+ nextDemo();
}
private function keyUp(e:KeyboardEvent):void {
if(e.keyCode == Keyboard.D) {
// simulate device loss
context3D.dispose();
} else if(e.keyCode == Keyboard.SPACE) {
- nextBtnClick();
+ nextDemo();
} else if(e.keyCode == Keyboard.F) {
stage.displayState = StageDisplayState.FULL_SCREEN;
}
}
- private function nextBtnClick():void {
+ private function nextDemo():void {
camera.reset();
@@ -32,9 +32,9 @@ package de.nulldesign.nd2d.display {
import de.nulldesign.nd2d.materials.texture.SpriteSheet;
import de.nulldesign.nd2d.materials.texture.Texture2D;
-
+
import flash.display.BitmapData;
-
+
import flashx.textLayout.formats.TextAlign;
public class BitmapFont2D extends Sprite2DCloud {
@@ -83,8 +83,9 @@ package de.nulldesign.nd2d.display {
if(textChanged) {
textChanged = false;
- var numSpaces:uint = text.split(" ").length - 1;
- var childsNeeded:uint = text.length - numSpaces;
+ const numSpaces:uint = text.split(" ").length - 1;
+ const text_length:int = text.length;
+ const childsNeeded:uint = text_length - numSpaces;
while(numChildren < maxCapacity && numChildren < childsNeeded) {
addChild(new Sprite2D());
@@ -103,15 +104,15 @@ package de.nulldesign.nd2d.display {
switch(textAlign) {
case TextAlign.CENTER:
- startX -= (text.length * spriteSheet.spriteWidth) >> 1;
+ startX -= (text_length * spriteSheet.spriteWidth) >> 1;
break;
case TextAlign.RIGHT:
- startX += -(text.length * spriteSheet.spriteWidth);
+ startX += -(text_length * spriteSheet.spriteWidth);
break;
}
- for(var i:int = 0; i < text.length; i++) {
+ for(var i:int = 0; i < text_length; i++) {
curChar = text.charAt(i);
frame = Math.max(0, charString.indexOf(curChar));
@@ -211,12 +211,8 @@ package de.nulldesign.nd2d.display {
indexBuffer = null;
uvInited = false;
- var c:Sprite2D;
- for(var i:int = 0; i < children.length; i++) {
- c = children[i] as Sprite2D;
- c.invalidateColors = true;
- c.invalidateMatrix = true;
- }
+ for each(var c:Sprite2D in children)
+ c.invalidateColors = c.invalidateMatrix = true;
}
override public function dispose():void {
@@ -260,7 +256,7 @@ package de.nulldesign.nd2d.display {
statsObject.totalTris += numTris;
}
- override public function updateColors():void {
+ override public function updateColors() : void {
super.updateColors();
isInvalidatedColors = true;
}
@@ -292,19 +288,19 @@ package de.nulldesign.nd2d.display {
var sr:Number;
var i:int = -1;
var child:Sprite2D;
- var n:uint = children.length;
+ const n:uint = children.length;
var sx:Number;
var sy:Number;
- var pivotX:Number, pivotY:Number;
- var offsetX:Number, offsetY:Number;
+ var pivotX: Number, pivotY: Number;
+ var offsetX: Number, offsetY: Number;
var somethingChanged:Boolean = false;
var atlasOffset:Point = new Point();
- var offsetFactor:Number = 1.0 / 255.0;
- var isChildInvalidatedColors:Boolean = false;
- var halfTextureWidth:Number = texture.textureWidth >> 1;
- var halfTextureHeight:Number = texture.textureHeight >> 1;
+ const offsetFactor:Number = 1.0 / 255.0;
+ var isChildInvalidatedColors : Boolean = false;
+ const halfTextureWidth : Number = texture.textureWidth >> 1;
+ const halfTextureHeight : Number = texture.textureHeight >> 1;
- if(invalidateColors) {
+ if(invalidateColors) {
updateColors();
isInvalidatedColors = true;
}
@@ -67,11 +67,11 @@ package de.nulldesign.nd2d.materials {
protected var mVertexBuffer:Vector.<Number>;
protected var shaderData:Shader2D;
- protected var programConstVector:Vector.<Number> = new Vector.<Number>(4);
+ protected var programConstVector:Vector.<Number> = new Vector.<Number>(4);
public static const VERTEX_POSITION:String = "PB3D_POSITION";
public static const VERTEX_UV:String = "PB3D_UV";
- public static const VERTEX_COLOR:String = "PB3D_COLOR";
+ public static const VERTEX_COLOR:String = "PB3D_COLOR";
public function AMaterial() {
@@ -86,7 +86,7 @@ package de.nulldesign.nd2d.materials {
initProgram(context);
var i:int;
- var numFaces:int = faceList.length;
+ const numFaces:int = faceList.length;
var numIndices:int;
mIndexBuffer = new Vector.<uint>();
@@ -148,11 +148,12 @@ package de.nulldesign.nd2d.materials {
vertexBuffer.uploadFromVector(mVertexBuffer, 0, numIndices);
if(!indexBuffer) {
+
+ const mIndexBuffer_length:int = mIndexBuffer.length;
+ indexBuffer = context.createIndexBuffer(mIndexBuffer_length);
+ indexBuffer.uploadFromVector(mIndexBuffer, 0, mIndexBuffer_length);
- indexBuffer = context.createIndexBuffer(mIndexBuffer.length);
- indexBuffer.uploadFromVector(mIndexBuffer, 0, mIndexBuffer.length);
-
- numTris = int(mIndexBuffer.length / 3);
+ numTris = int(mIndexBuffer_length / 3);
}
}
@@ -229,10 +230,10 @@ package de.nulldesign.nd2d.materials {
buffer.push(0.0, 0.0);
}
- if(semanticsID == VERTEX_COLOR) {
+ if(semanticsID == VERTEX_COLOR) {
buffer.push(v.r, v.g, v.b);
- if(floatFormat == 4)
+ if(floatFormat == 4)
buffer.push(v.a);
}
}
@@ -84,7 +84,7 @@ package de.nulldesign.nd2d.materials {
public function modifyColorInBuffer(bufferIdx:uint, r:Number, g:Number, b:Number, a:Number):void {
if(!mVertexBuffer || mVertexBuffer.length == 0) return;
- var idx:uint = bufferIdx * shaderData.numFloatsPerVertex;
+ const idx:uint = bufferIdx * shaderData.numFloatsPerVertex;
mVertexBuffer[idx + 2] = r;
mVertexBuffer[idx + 3] = g;
@@ -143,11 +143,11 @@ package de.nulldesign.nd2d.materials {
protected function processAndRenderNodes(context:Context3D, childList:Vector.<Node2D>):void {
var child:Sprite2D;
- var colorMultiplierAndOffset:Vector.<Number> = new Vector.<Number>(8, true);
- var uvoffset:Vector.<Number> = new Vector.<Number>(4, true);
+ const colorMultiplierAndOffset:Vector.<Number> = new Vector.<Number>(8, true);
+ const uvoffset:Vector.<Number> = new Vector.<Number>(4, true);
var i:int = -1;
- var n:int = childList.length;
- var offsetFactor:Number = 1.0 / 255.0;
+ const n:int = childList.length;
+ const offsetFactor:Number = 1.0 / 255.0;
while(++i < n) {
@@ -164,7 +164,7 @@ package de.nulldesign.nd2d.materials {
public function modifyVertexInBuffer(bufferIdx:uint, x:Number, y:Number):void {
if(!mVertexBuffer || mVertexBuffer.length == 0) return;
- var idx:uint = bufferIdx * shaderData.numFloatsPerVertex;
+ const idx:uint = bufferIdx * shaderData.numFloatsPerVertex;
mVertexBuffer[idx] = x;
mVertexBuffer[idx + 1] = y;
@@ -165,12 +165,12 @@ package de.nulldesign.nd2d.materials.texture {
}
/*
// calculate real offset
- var idx:uint = sourceColorRects.length - 1;
- var offset:Point = offsets[idx];
- var sourceFrame:Rectangle = frames[idx];
- var sourceColorRect:Rectangle = sourceColorRects[idx];
- var sourceSize:Point = sourceSizes[idx];
- var newOffset:Point = new Point((sourceSize.x - sourceFrame.width) / 2 - sourceColorRect.x, (sourceSize.y - sourceFrame.height) / 2 - sourceColorRect.y);
+ const idx:uint = sourceColorRects.length - 1;
+ const offset:Point = offsets[idx];
+ const sourceFrame:Rectangle = frames[idx];
+ const sourceColorRect:Rectangle = sourceColorRects[idx];
+ const sourceSize:Point = sourceSizes[idx];
+ const newOffset:Point = new Point((sourceSize.x - sourceFrame.width) / 2 - sourceColorRect.x, (sourceSize.y - sourceFrame.height) / 2 - sourceColorRect.y);
offset.x = -newOffset.x;
offset.y = -newOffset.y;
@@ -181,11 +181,12 @@ package de.nulldesign.nd2d.materials.texture {
}
}
- if(frames.length == 0) {
+ const frames_length:int = frames.length;
+ if(frames_length == 0) {
throw new Error("Error parsing descriptor format");
}
- uvRects = new Vector.<Rectangle>(frames.length, true);
+ uvRects = new Vector.<Rectangle>(frames_length, true);
frame = 0;
/*

0 comments on commit 8856ce9

Please sign in to comment.