Skip to content

Commit

Permalink
test, debug rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
elsassph committed Jun 17, 2013
1 parent 4494d10 commit eced75a
Show file tree
Hide file tree
Showing 8 changed files with 400 additions and 11 deletions.
4 changes: 2 additions & 2 deletions haxelib/aze/display/TileLayer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class TileLayer extends TileGroup
var off:Point = sprite.offset;
if (offsetTransform > 0) {
var t = sprite.transform;
list[index] = sprite.x - off.x * t[0] - off.y * t[1] + gx;
list[index+1] = sprite.y - off.x * t[2] - off.y * t[3] + gy;
list[index] = sprite.x - off.x * t[0] - off.y * t[2] + gx;
list[index+1] = sprite.y - off.x * t[1] - off.y * t[3] + gy;
list[index+offsetTransform] = t[0];
list[index+offsetTransform+1] = t[1];
list[index+offsetTransform+2] = t[2];
Expand Down
9 changes: 2 additions & 7 deletions haxelib/aze/display/TileSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,8 @@ class TileSprite extends TileBase
var cos = Math.cos(rotation);
var sin = Math.sin(rotation);
_transform[0] = dirX * cos * sx;
#if js
_transform[1] = dirY * sin * sy;
_transform[2] = -dirX * sin * sx;
#else
_transform[2] = dirY * sin * sy;
_transform[1] = -dirX * sin * sx;
#end
_transform[1] = dirX * sin * sx;
_transform[2] = -dirY * sin * sy;
_transform[3] = dirY * cos * sy;
}
else {
Expand Down
4 changes: 2 additions & 2 deletions haxelib/haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"license": "MIT",
"tags": ["openfl","nme"],
"description": "Lightweight wrapper over OpenFL's powerful but lowlevel 'drawTiles', with bitmap-based fallback for Flash. Includes a Sparrow spritesheets parser supporting animations and trimming.",
"version": "0.0.1",
"releasenote": "This is the first iteration of porting nme-tilelayer to work with Haxe 3 and Openfl",
"version": "0.1",
"releasenote": "In sync with nme-tilelayer, addition of a test project",
"contributors": ["elsassph", "matthewswallace"],
"dependencies":
{
Expand Down
28 changes: 28 additions & 0 deletions test/application.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<!-- NMML reference: https://gist.github.com/1763850 -->

<!-- metadata, make sure 'package' is at least 3 segments (ie. com.mycompany.myproject) -->
<meta title="test" package="test" version="1.0.0" company="Philippe" />

<!-- output -->
<app main="Main" file="tost" path="bin" />

<window background="#000000" fps="60" />
<window width="800" height="480" unless="mobile" />
<window orientation="landscape" vsync="false" antialiasing="0" if="cpp" />

<!-- classpath, haxe libs -->
<source path="src" />
<!--<haxelib name="tilelayer" />-->
<source name="../haxelib" />
<haxelib name="openfl" />

<!-- assets -->
<icon path="assets/nme.svg" />
<assets path="assets/img" rename="img" />

<!-- optimize output -->
<haxeflag name="-dce std" />

</project>
Binary file added test/assets/img/wabbit_alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions test/assets/nme.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
292 changes: 292 additions & 0 deletions test/src/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
package ;

import aze.display.behaviours.TileGroupTransform;
import aze.display.TileGroup;
import aze.display.TileLayer;
import aze.display.TilesheetEx;
import aze.display.TileSprite;
import openfl.Assets;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.Lib;

/**
* ...
* @author Philippe
*/

class Main extends Sprite
{
var inited:Bool;
var layer:TileLayer;
var bunny:TileSprite;
var group:TileGroup;
var groupTransform:TileGroupTransform;
var k:Float;

/* ENTRY POINT */

function resize(e)
{
if (!inited) init();
// else (resize or orientation change)
}

function init()
{
if (inited) return;
inited = true;

var bmp = Assets.getBitmapData("img/wabbit_alpha.png");
var r:Rectangle = cast bmp.rect.clone();
var sheet:TilesheetEx = new TilesheetEx(bmp);
#if flash
sheet.addDefinition("bunny", r, bmp);
#else
sheet.addDefinition("bunny", r, r, new Point(r.width/2, r.height/2));
#end

layer = new TileLayer(sheet, false);
addChild(layer.view);

k = 100;

/* COL 1 */

var bunny = new TileSprite(layer, "bunny");
bunny.x = k;
bunny.y = k;
layer.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k*2;
bunny.y = k;
bunny.scale = 2;
layer.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k*3;
bunny.y = k;
bunny.scaleX = 2;
bunny.scaleY = 0.5;
layer.addChild(bunny);

var bunny = new TileSprite(layer, "bunny");
bunny.x = k;
bunny.y = k*2;
bunny.rotation = 0.5;
layer.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k*2;
bunny.y = k*2;
bunny.scale = 2;
bunny.rotation = 0.5;
layer.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k*3;
bunny.y = k*2;
bunny.scaleX = 2;
bunny.scaleY = 0.5;
bunny.rotation = 0.5;
layer.addChild(bunny);

/* COL 1 GROUP 1 */

var g = new TileGroup(layer);
g.y = k * 3;
layer.addChild(g);

var bunny = new TileSprite(layer, "bunny");
bunny.x = k;
bunny.y = 0;
g.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k*2;
bunny.y = 0;
bunny.scale = 2;
g.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k*3;
bunny.y = 0;
bunny.scaleX = 2;
bunny.scaleY = 0.5;
g.addChild(bunny);

var bunny = new TileSprite(layer, "bunny");
bunny.x = k;
bunny.y = k;
bunny.rotation = 0.5;
g.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k*2;
bunny.y = k;
bunny.scale = 2;
bunny.rotation = 0.5;
g.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k*3;
bunny.y = k;
bunny.scaleX = 2;
bunny.scaleY = 0.5;
bunny.rotation = 0.5;
g.addChild(bunny);

/* COL 2 */

var p = new Point( -r.width / 2, -r.height / 2);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k*3+k;
bunny.y = 0;
bunny.offset = p;
layer.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k*3+k*2;
bunny.y = 0;
bunny.scale = 2;
bunny.offset = p;
layer.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k*3+k*3;
bunny.y = 0;
bunny.scaleX = 2;
bunny.scaleY = 0.5;
bunny.offset = p;
layer.addChild(bunny);

var bunny = new TileSprite(layer, "bunny");
bunny.x = k*3+k;
bunny.y = k;
bunny.rotation = 0.5;
bunny.offset = p;
layer.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k*3+k*2;
bunny.y = k;
bunny.scale = 2;
bunny.rotation = 0.5;
bunny.offset = p;
layer.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k*3+k*3;
bunny.y = k;
bunny.scaleX = 2;
bunny.scaleY = 0.5;
bunny.rotation = 0.5;
bunny.offset = p;
layer.addChild(bunny);

/* COL 2 GROUP 2 */

g = new TileGroup(layer);
g.x = k * 5;
g.y = k * 3;
layer.addChild(g);
group = g;

var p = new Point( -r.width / 2, -r.height / 2);
var bunny = new TileSprite(layer, "bunny");
bunny.x = -k;
bunny.y = -k;
bunny.offset = p;
g.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = 0;
bunny.y = -k;
bunny.scale = 2;
bunny.offset = p;
g.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k;
bunny.y = -k;
bunny.scaleX = 2;
bunny.scaleY = 0.5;
bunny.offset = p;
g.addChild(bunny);

var bunny = new TileSprite(layer, "bunny");
bunny.x = -k;
bunny.y = 0;
bunny.rotation = 0.5;
bunny.offset = p;
g.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = 0;
bunny.y = 0;
bunny.scale = 2;
bunny.rotation = 0.5;
bunny.offset = p;
g.addChild(bunny);
var bunny = new TileSprite(layer, "bunny");
bunny.x = k;
bunny.y = 0;
bunny.scaleX = 2;
bunny.scaleY = 0.5;
bunny.rotation = 0.5;
bunny.offset = p;
g.addChild(bunny);

groupTransform = new TileGroupTransform(g);


/* GRID */

var grid:Shape = new Shape();
for (i in 0...Std.int(stage.stageWidth / k))
{
grid.graphics.lineStyle(i == 2 ? 4 : 1, 0xff0000, 0.5);
grid.graphics.moveTo((i+1) * k, 0);
grid.graphics.lineTo((i+1) * k, stage.stageHeight);
}
for (i in 0...Std.int(stage.stageHeight/k))
{
grid.graphics.lineStyle(i == 2 ? 4 : 1, 0xff0000, 0.5);
grid.graphics.moveTo(0, (i+1) * k);
grid.graphics.lineTo(stage.stageWidth, (i+1) * k);
}
grid.graphics.drawCircle(k * 5, k * 3, k * 2);
addChild(grid);

addEventListener(Event.ENTER_FRAME, enterFrame);
}

private function enterFrame(e:Event):Void
{
var dx = group.x - stage.mouseX;
var dy = group.y - stage.mouseY;
var d = Math.sqrt(dx * dx + dy * dy);
var a = Math.atan2(dy, dx);
groupTransform.rotation = a;
groupTransform.scale = Math.max(d, k) / (k * 2);
groupTransform.update();

layer.render();
}

/* SETUP */

public function new()
{
super();
addEventListener(Event.ADDED_TO_STAGE, added);
}

function added(e)
{
removeEventListener(Event.ADDED_TO_STAGE, added);
stage.addEventListener(Event.RESIZE, resize);
#if ios
haxe.Timer.delay(init, 100); // iOS 6
#else
init();
#end
}

public static function main()
{
// static entry point
Lib.current.stage.align = flash.display.StageAlign.TOP_LEFT;
Lib.current.stage.scaleMode = flash.display.StageScaleMode.NO_SCALE;
Lib.current.addChild(new Main());
}
}
Loading

0 comments on commit eced75a

Please sign in to comment.