Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions haxelib/aze/display/SparrowTilesheet.hx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package aze.display;

import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.Lib;
import openfl.display.BitmapData;
import openfl.geom.Point;
import openfl.geom.Rectangle;
import openfl.Lib;

/**
parrow spritesheet parser for TileLayer
Expand All @@ -15,7 +15,14 @@ parrow spritesheet parser for TileLayer
class SparrowTilesheet extends TilesheetEx
{

public function new(img:BitmapData, xml:String, textureScale:Float = 1.0)
/**
*
* @param img texture atlas
* @param xml
* @param textureScale
* @param useCenterPoint default value = true, false means that the center point will be top left
*/
public function new(img:BitmapData, xml:String, textureScale:Float = 1.0, useCenterPoint:Bool = true)
{
super(img, textureScale);

Expand All @@ -36,16 +43,17 @@ class SparrowTilesheet extends TilesheetEx
else
new Rectangle(0, 0, rect.width, rect.height);

//trace([name, rect.x, rect.y, rect.width, rect.height, size.x, size.y, size.width, size.height]);

#if flash
var bmp = new BitmapData(cast size.width, cast size.height, true, 0);
ins.x = -size.left;
ins.y = -size.top;
bmp.copyPixels(img, rect, ins);
addDefinition(name, size, bmp);
#else
var center = new Point((size.x + size.width / 2), (size.y + size.height / 2));
var center = if (useCenterPoint)
new Point((size.x + size.width / 2), (size.y + size.height / 2))
else
texture.has.frameX ? new Point(size.x, size.y) : null;
addDefinition(name, size, rect, center);
#end
}
Expand Down
5 changes: 3 additions & 2 deletions haxelib/aze/display/TileGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package aze.display;
import aze.display.TileLayer;
import aze.display.TileGroup;
import aze.display.TileSprite;
import flash.display.DisplayObject;
import flash.display.Sprite;

import openfl.display.DisplayObject;
import openfl.display.Sprite;

/**
* Tiles container for TileLayer
Expand Down
70 changes: 29 additions & 41 deletions haxelib/aze/display/TileLayer.hx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package aze.display;

import flash.geom.Point;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.DisplayObject;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.Lib;
import openfl.display.Bitmap;
import openfl.display.BitmapData;
import openfl.display.BlendMode;
import openfl.display.DisplayObject;
import openfl.display.Graphics;
import openfl.display.Sprite;
import openfl.geom.Matrix;
import openfl.geom.Point;
import openfl.geom.Rectangle;
import openfl.Lib;

/**
* A little wrapper of NME's Tilesheet rendering (for native platform)
Expand Down Expand Up @@ -79,7 +79,7 @@ class TileLayer extends TileGroup
gx += group.x;
gy += group.y;
#end

var n = group.numChildren;
for(i in 0...n)
{
Expand All @@ -90,7 +90,7 @@ class TileLayer extends TileGroup
if (!child.visible) continue;
#end

#if (flash||js)
#if (flash || js || neko)
var group:TileGroup = Std.is(child, TileGroup) ? cast child : null;
#else
var group:TileGroup = cast child;
Expand All @@ -105,10 +105,11 @@ class TileLayer extends TileGroup
var sprite:TileSprite = cast child;

#if flash
if (sprite.visible && sprite.alpha > 0.0)
if (sprite.parent.visible && sprite.visible && sprite.alpha > 0.0)
{
var m = sprite.bmp.transform.matrix;
m.identity();
if (sprite.offset != null) m.translate(-sprite.offset.x, -sprite.offset.y);
m.concat(sprite.matrix);
m.translate(sprite.x, sprite.y);
sprite.bmp.transform.matrix = m;
Expand All @@ -122,17 +123,17 @@ class TileLayer extends TileGroup
#else
if (sprite.alpha <= 0.0) continue;
list[index+2] = sprite.indice;

if (sprite.offset != null)
{
var off:Point = sprite.offset;
var off:Point = sprite.offset;
if (offsetTransform > 0) {
var t = sprite.transform;
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] = 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+offsetTransform] = t[0];
list[index+offsetTransform+1] = t[1];
list[index+offsetTransform+2] = t[2];
list[index+offsetTransform+1] = t[2];
list[index+offsetTransform+2] = t[1];
list[index+offsetTransform+3] = t[3];
}
else {
Expand All @@ -146,12 +147,12 @@ class TileLayer extends TileGroup
if (offsetTransform > 0) {
var t = sprite.transform;
list[index+offsetTransform] = t[0];
list[index+offsetTransform+1] = t[1];
list[index+offsetTransform+2] = t[2];
list[index+offsetTransform+1] = t[2];
list[index+offsetTransform+2] = t[1];
list[index+offsetTransform+3] = t[3];
}
}

if (offsetRGB > 0) {
list[index+offsetRGB] = sprite.r;
list[index+offsetRGB+1] = sprite.g;
Expand All @@ -171,7 +172,6 @@ class TileLayer extends TileGroup
/**
* @private base tile type
*/

class TileBase
{
public var layer:TileLayer;
Expand All @@ -181,14 +181,14 @@ class TileBase
public var animated:Bool;
public var visible:Bool;

function new(layer:TileLayer)
public function new(layer:TileLayer)
{
this.layer = layer;
x = y = 0.0;
visible = true;
}

function init(layer:TileLayer):Void
public function init(layer:TileLayer):Void
{
this.layer = layer;
}
Expand All @@ -198,19 +198,15 @@ class TileBase
}

#if flash
function getView():DisplayObject { return null; }
public function getView():DisplayObject { return null; }
#end
}


/**
* @private render buffer
*/
#if haxe3
class DrawList
#else
class DrawList implements Public
#end
private class DrawList
{
public var list:Array<Float>;
public var index:Int;
Expand All @@ -223,22 +219,14 @@ class TileBase
public var elapsed:Int;
public var runs:Int;

#if haxe3
public function new()
#else
function new()
#end
public function new()
{
list = new Array<Float>();
elapsed = 0;
runs = 0;
}

#if haxe3
public function begin(elapsed:Int, useTransforms:Bool, useAlpha:Bool, useTint:Bool, useAdditive:Bool)
#else
function begin(elapsed:Int, useTransforms:Bool, useAlpha:Bool, useTint:Bool, useAdditive:Bool)
#end
public function begin(elapsed:Int, useTransforms:Bool, useAlpha:Bool, useTint:Bool, useAdditive:Bool)
{
#if !flash
flags = 0;
Expand Down
Loading