新增ninja adventure例子
This commit is contained in:
Vendored
+16
@@ -658,6 +658,7 @@ declare module es {
|
||||
origin: Vector2;
|
||||
readonly uvs: Rectangle;
|
||||
constructor(texture: egret.Texture, sourceRect?: Rectangle, origin?: Vector2);
|
||||
static spritesFromAtlas(texture: egret.Texture, cellWidth: number, cellHeight: number, cellOffset?: number, maxCellsToInclude?: number): Sprite[];
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
@@ -1331,6 +1332,21 @@ declare module es {
|
||||
calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class SubpixelFloat {
|
||||
remainder: number;
|
||||
update(amount: number): number;
|
||||
reset(): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class SubpixelVector2 {
|
||||
_x: SubpixelFloat;
|
||||
_y: SubpixelFloat;
|
||||
update(amount: Vector2): void;
|
||||
reset(): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class Vector3 {
|
||||
x: number;
|
||||
|
||||
@@ -1255,7 +1255,8 @@ var es;
|
||||
this._scene.update();
|
||||
}
|
||||
if (!this._nextScene) return [3, 2];
|
||||
this.removeChild(this._scene);
|
||||
if (this._scene.parent)
|
||||
this._scene.parent.removeChild(this._scene);
|
||||
this._scene.end();
|
||||
this._scene = this._nextScene;
|
||||
this._nextScene = null;
|
||||
@@ -3094,6 +3095,7 @@ var es;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var SpriteSheet = egret.SpriteSheet;
|
||||
var Sprite = (function () {
|
||||
function Sprite(texture, sourceRect, origin) {
|
||||
if (sourceRect === void 0) { sourceRect = new es.Rectangle(0, 0, texture.textureWidth, texture.textureHeight); }
|
||||
@@ -3110,6 +3112,28 @@ var es;
|
||||
this.uvs.width = sourceRect.width * inverseTexW;
|
||||
this.uvs.height = sourceRect.height * inverseTexH;
|
||||
}
|
||||
Sprite.spritesFromAtlas = function (texture, cellWidth, cellHeight, cellOffset, maxCellsToInclude) {
|
||||
if (cellOffset === void 0) { cellOffset = 0; }
|
||||
if (maxCellsToInclude === void 0) { maxCellsToInclude = Number.MAX_VALUE; }
|
||||
var sprites = [];
|
||||
var cols = texture.textureWidth / cellWidth;
|
||||
var rows = texture.textureHeight / cellHeight;
|
||||
var i = 0;
|
||||
var spriteSheet = new SpriteSheet(texture);
|
||||
for (var y = 0; y < rows; y++) {
|
||||
for (var x = 0; x < cols; x++) {
|
||||
if (i++ < cellOffset)
|
||||
continue;
|
||||
var texture_1 = spriteSheet.getTexture(y + "_" + x);
|
||||
if (!texture_1)
|
||||
texture_1 = spriteSheet.createTexture(y + "_" + x, x * cellWidth, y * cellHeight, cellWidth, cellHeight);
|
||||
sprites.push(new Sprite(texture_1));
|
||||
if (sprites.length == maxCellsToInclude)
|
||||
return sprites;
|
||||
}
|
||||
}
|
||||
return sprites;
|
||||
};
|
||||
return Sprite;
|
||||
}());
|
||||
es.Sprite = Sprite;
|
||||
@@ -3179,7 +3203,7 @@ var es;
|
||||
this.animationState = State.completed;
|
||||
this._elapsedTime = 0;
|
||||
this.currentFrame = 0;
|
||||
this.sprite = animation.sprites[this.currentFrame];
|
||||
this.displayObject.texture = animation.sprites[this.currentFrame].texture2D;
|
||||
return;
|
||||
}
|
||||
var i = Math.floor(time / secondsPerFrame);
|
||||
@@ -3191,7 +3215,7 @@ var es;
|
||||
else {
|
||||
this.currentFrame = i % n;
|
||||
}
|
||||
this.sprite = animation.sprites[this.currentFrame];
|
||||
this.displayObject.texture = animation.sprites[this.currentFrame].texture2D;
|
||||
};
|
||||
SpriteAnimator.prototype.addAnimation = function (name, animation) {
|
||||
if (!this.sprite && animation.sprites.length > 0)
|
||||
@@ -3205,7 +3229,7 @@ var es;
|
||||
this.currentAnimationName = name;
|
||||
this.currentFrame = 0;
|
||||
this.animationState = State.running;
|
||||
this.sprite = this.currentAnimation.sprites[0];
|
||||
this.displayObject.texture = this.currentAnimation.sprites[0].texture2D;
|
||||
this._elapsedTime = 0;
|
||||
this._loopMode = loopMode ? loopMode : LoopMode.loop;
|
||||
};
|
||||
@@ -4154,7 +4178,8 @@ var es;
|
||||
};
|
||||
ComponentList.prototype.handleRemove = function (component) {
|
||||
if (component instanceof es.RenderableComponent) {
|
||||
this._entity.scene.removeChild(component.displayObject);
|
||||
if (component.displayObject.parent)
|
||||
component.displayObject.parent.removeChild(component.displayObject);
|
||||
this._entity.scene.renderableComponents.remove(component);
|
||||
}
|
||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
|
||||
@@ -4727,7 +4752,7 @@ var es;
|
||||
var component = this_1._components[i];
|
||||
var egretDisplayObject = scene.$children.find(function (a) { return a.hashCode == component.displayObject.hashCode; });
|
||||
var displayIndex = scene.getChildIndex(egretDisplayObject);
|
||||
if (displayIndex != i)
|
||||
if (displayIndex != -1 && displayIndex != i)
|
||||
scene.swapChildrenAt(displayIndex, i);
|
||||
};
|
||||
var this_1 = this;
|
||||
@@ -6384,6 +6409,45 @@ var es;
|
||||
es.Rectangle = Rectangle;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var SubpixelFloat = (function () {
|
||||
function SubpixelFloat() {
|
||||
this.remainder = 0;
|
||||
}
|
||||
SubpixelFloat.prototype.update = function (amount) {
|
||||
this.remainder += amount;
|
||||
var motion = Math.trunc(this.remainder);
|
||||
this.remainder -= motion;
|
||||
amount = motion;
|
||||
return amount;
|
||||
};
|
||||
SubpixelFloat.prototype.reset = function () {
|
||||
this.remainder = 0;
|
||||
};
|
||||
return SubpixelFloat;
|
||||
}());
|
||||
es.SubpixelFloat = SubpixelFloat;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var SubpixelVector2 = (function () {
|
||||
function SubpixelVector2() {
|
||||
this._x = new es.SubpixelFloat();
|
||||
this._y = new es.SubpixelFloat();
|
||||
}
|
||||
SubpixelVector2.prototype.update = function (amount) {
|
||||
amount.x = this._x.update(amount.x);
|
||||
amount.y = this._y.update(amount.y);
|
||||
};
|
||||
SubpixelVector2.prototype.reset = function () {
|
||||
this._x.reset();
|
||||
this._y.reset();
|
||||
};
|
||||
return SubpixelVector2;
|
||||
}());
|
||||
es.SubpixelVector2 = SubpixelVector2;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var Vector3 = (function () {
|
||||
function Vector3(x, y, z) {
|
||||
@@ -9441,7 +9505,8 @@ var es;
|
||||
ContentManager.prototype.dispose = function () {
|
||||
this.loadedAssets.forEach(function (value) {
|
||||
var assetsToRemove = value;
|
||||
assetsToRemove.dispose();
|
||||
if (RES.destroyRes(assetsToRemove))
|
||||
assetsToRemove.dispose();
|
||||
});
|
||||
this.loadedAssets.clear();
|
||||
};
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+4
-2
@@ -17,7 +17,7 @@
|
||||
"bin-debug/UI/mvc/BaseView.js",
|
||||
"bin-debug/SampleHelpers/SampleScene.js",
|
||||
"bin-debug/UI/loading/LoadingView.js",
|
||||
"bin-debug/Scenes/LineCasting/LineCaster.js",
|
||||
"bin-debug/Scenes/LineCasting/LineCastingScene.js",
|
||||
"bin-debug/Fgui/common/UI_com_tips.js",
|
||||
"bin-debug/Fgui/loading/loadingBinder.js",
|
||||
"bin-debug/Fgui/loading/UI_View_loading.js",
|
||||
@@ -27,8 +27,10 @@
|
||||
"bin-debug/Platform.js",
|
||||
"bin-debug/Scenes/Animated Tiles/AnimatedTilesScene.js",
|
||||
"bin-debug/Scenes/Empty Scene/BasicScene.js",
|
||||
"bin-debug/Scenes/LineCasting/LineCaster.js",
|
||||
"bin-debug/Main.js",
|
||||
"bin-debug/Scenes/LineCasting/LineCastingScene.js",
|
||||
"bin-debug/Scenes/Ninja Adventure/Ninja.js",
|
||||
"bin-debug/Scenes/Ninja Adventure/NinjaAdventureScene.js",
|
||||
"bin-debug/UI/PopManager.js",
|
||||
"bin-debug/UI/loading/LoadingControl.js",
|
||||
"bin-debug/UI/loading/LoadingEvents.js",
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.9 KiB |
@@ -15,6 +15,10 @@
|
||||
{
|
||||
"keys": "common",
|
||||
"name": "common"
|
||||
},
|
||||
{
|
||||
"keys": "1_png,2_png,3_png,4_png,5_png,6_png",
|
||||
"name": "characters"
|
||||
}
|
||||
],
|
||||
"resources": [
|
||||
@@ -67,6 +71,36 @@
|
||||
"url": "preload/orthogonal-outside.json",
|
||||
"type": "json",
|
||||
"name": "orthogonal-outside_json"
|
||||
},
|
||||
{
|
||||
"url": "characters/1.png",
|
||||
"type": "image",
|
||||
"name": "1_png"
|
||||
},
|
||||
{
|
||||
"url": "characters/2.png",
|
||||
"type": "image",
|
||||
"name": "2_png"
|
||||
},
|
||||
{
|
||||
"url": "characters/3.png",
|
||||
"type": "image",
|
||||
"name": "3_png"
|
||||
},
|
||||
{
|
||||
"url": "characters/4.png",
|
||||
"type": "image",
|
||||
"name": "4_png"
|
||||
},
|
||||
{
|
||||
"url": "characters/5.png",
|
||||
"type": "image",
|
||||
"name": "5_png"
|
||||
},
|
||||
{
|
||||
"url": "characters/6.png",
|
||||
"type": "image",
|
||||
"name": "6_png"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
module samples {
|
||||
import SpriteAnimator = es.SpriteAnimator;
|
||||
import Mover = es.Mover;
|
||||
|
||||
export class Ninja extends es.Component {
|
||||
public _animator: SpriteAnimator;
|
||||
|
||||
public _mover: Mover;
|
||||
|
||||
public onAddedToEntity(): void {
|
||||
let characterPng = RandomUtils.randint(1, 6);
|
||||
this.entity.scene.content.loadRes(`${characterPng}_png`).then(texture => {
|
||||
let sprites = es.Sprite.spritesFromAtlas(texture, 16, 16);
|
||||
|
||||
this._mover = this.entity.addComponent(new Mover());
|
||||
this._animator = this.entity.addComponent(new SpriteAnimator());
|
||||
|
||||
this._animator.addAnimation("walkLeft", new es.SpriteAnimation([
|
||||
sprites[2],
|
||||
sprites[6],
|
||||
sprites[10],
|
||||
sprites[14]
|
||||
], 4));
|
||||
|
||||
this._animator.addAnimation("walkRight", new es.SpriteAnimation([
|
||||
sprites[3],
|
||||
sprites[7],
|
||||
sprites[11],
|
||||
sprites[15]
|
||||
], 4));
|
||||
|
||||
this._animator.addAnimation("walkDown", new es.SpriteAnimation([
|
||||
sprites[0],
|
||||
sprites[4],
|
||||
sprites[8],
|
||||
sprites[12]
|
||||
], 4));
|
||||
|
||||
this._animator.addAnimation("walkUp", new es.SpriteAnimation([
|
||||
sprites[1],
|
||||
sprites[5],
|
||||
sprites[9],
|
||||
sprites[13]
|
||||
], 4));
|
||||
|
||||
this._animator.play("walkDown");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
module samples {
|
||||
import CircleCollider = es.CircleCollider;
|
||||
import Flags = es.Flags;
|
||||
import SpriteRenderer = es.SpriteRenderer;
|
||||
|
||||
export class NinjaAdventureScene extends SampleScene {
|
||||
constructor() {
|
||||
super(true, true);
|
||||
}
|
||||
|
||||
public initialize(): void {
|
||||
super.initialize();
|
||||
|
||||
let playerEntity = this.createEntity("player");
|
||||
playerEntity.position = new es.Vector2(256, 224);
|
||||
playerEntity.addComponent(new Ninja());
|
||||
let collider = playerEntity.addComponent(new CircleCollider());
|
||||
|
||||
// 我们只希望与默认图层0上的组件发生冲突
|
||||
Flags.setFlagExclusive(collider.collidesWithLayers, 0);
|
||||
// 移动到第1层 保证自己的图层不会如果增加攻击方式则不会攻击到自身
|
||||
Flags.setFlagExclusive(collider.physicsLayer, 1);
|
||||
|
||||
this.content.loadRes("moon_png").then(moonTexture => {
|
||||
let moonEntity = this.createEntity("moon");
|
||||
moonEntity.position = new es.Vector2(412, 460);
|
||||
moonEntity.addComponent(new SpriteRenderer(moonTexture));
|
||||
moonEntity.addComponent(new CircleCollider());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ module loading {
|
||||
|
||||
export class LoadingView extends BaseView implements RES.PromiseTaskReporter {
|
||||
private _ui: FUI.loading.UI_View_loading;
|
||||
private _loadGroup = ["preload", "common"];
|
||||
private _loadGroup = ["preload", "common", "characters"];
|
||||
private _maxProgress = 0;
|
||||
private _currentProgress = 0;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ module sc {
|
||||
new SceneData("空白场景", samples.BasicScene),
|
||||
new SceneData("Tiled Tiles", samples.AnimatedTilesScene),
|
||||
new SceneData("Linecasting", samples.LineCastingScene),
|
||||
new SceneData("Ninja Adventure", samples.NinjaAdventureScene),
|
||||
];
|
||||
|
||||
constructor() {
|
||||
|
||||
Vendored
+16
@@ -658,6 +658,7 @@ declare module es {
|
||||
origin: Vector2;
|
||||
readonly uvs: Rectangle;
|
||||
constructor(texture: egret.Texture, sourceRect?: Rectangle, origin?: Vector2);
|
||||
static spritesFromAtlas(texture: egret.Texture, cellWidth: number, cellHeight: number, cellOffset?: number, maxCellsToInclude?: number): Sprite[];
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
@@ -1331,6 +1332,21 @@ declare module es {
|
||||
calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class SubpixelFloat {
|
||||
remainder: number;
|
||||
update(amount: number): number;
|
||||
reset(): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class SubpixelVector2 {
|
||||
_x: SubpixelFloat;
|
||||
_y: SubpixelFloat;
|
||||
update(amount: Vector2): void;
|
||||
reset(): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class Vector3 {
|
||||
x: number;
|
||||
|
||||
+72
-7
@@ -1255,7 +1255,8 @@ var es;
|
||||
this._scene.update();
|
||||
}
|
||||
if (!this._nextScene) return [3, 2];
|
||||
this.removeChild(this._scene);
|
||||
if (this._scene.parent)
|
||||
this._scene.parent.removeChild(this._scene);
|
||||
this._scene.end();
|
||||
this._scene = this._nextScene;
|
||||
this._nextScene = null;
|
||||
@@ -3094,6 +3095,7 @@ var es;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var SpriteSheet = egret.SpriteSheet;
|
||||
var Sprite = (function () {
|
||||
function Sprite(texture, sourceRect, origin) {
|
||||
if (sourceRect === void 0) { sourceRect = new es.Rectangle(0, 0, texture.textureWidth, texture.textureHeight); }
|
||||
@@ -3110,6 +3112,28 @@ var es;
|
||||
this.uvs.width = sourceRect.width * inverseTexW;
|
||||
this.uvs.height = sourceRect.height * inverseTexH;
|
||||
}
|
||||
Sprite.spritesFromAtlas = function (texture, cellWidth, cellHeight, cellOffset, maxCellsToInclude) {
|
||||
if (cellOffset === void 0) { cellOffset = 0; }
|
||||
if (maxCellsToInclude === void 0) { maxCellsToInclude = Number.MAX_VALUE; }
|
||||
var sprites = [];
|
||||
var cols = texture.textureWidth / cellWidth;
|
||||
var rows = texture.textureHeight / cellHeight;
|
||||
var i = 0;
|
||||
var spriteSheet = new SpriteSheet(texture);
|
||||
for (var y = 0; y < rows; y++) {
|
||||
for (var x = 0; x < cols; x++) {
|
||||
if (i++ < cellOffset)
|
||||
continue;
|
||||
var texture_1 = spriteSheet.getTexture(y + "_" + x);
|
||||
if (!texture_1)
|
||||
texture_1 = spriteSheet.createTexture(y + "_" + x, x * cellWidth, y * cellHeight, cellWidth, cellHeight);
|
||||
sprites.push(new Sprite(texture_1));
|
||||
if (sprites.length == maxCellsToInclude)
|
||||
return sprites;
|
||||
}
|
||||
}
|
||||
return sprites;
|
||||
};
|
||||
return Sprite;
|
||||
}());
|
||||
es.Sprite = Sprite;
|
||||
@@ -3179,7 +3203,7 @@ var es;
|
||||
this.animationState = State.completed;
|
||||
this._elapsedTime = 0;
|
||||
this.currentFrame = 0;
|
||||
this.sprite = animation.sprites[this.currentFrame];
|
||||
this.displayObject.texture = animation.sprites[this.currentFrame].texture2D;
|
||||
return;
|
||||
}
|
||||
var i = Math.floor(time / secondsPerFrame);
|
||||
@@ -3191,7 +3215,7 @@ var es;
|
||||
else {
|
||||
this.currentFrame = i % n;
|
||||
}
|
||||
this.sprite = animation.sprites[this.currentFrame];
|
||||
this.displayObject.texture = animation.sprites[this.currentFrame].texture2D;
|
||||
};
|
||||
SpriteAnimator.prototype.addAnimation = function (name, animation) {
|
||||
if (!this.sprite && animation.sprites.length > 0)
|
||||
@@ -3205,7 +3229,7 @@ var es;
|
||||
this.currentAnimationName = name;
|
||||
this.currentFrame = 0;
|
||||
this.animationState = State.running;
|
||||
this.sprite = this.currentAnimation.sprites[0];
|
||||
this.displayObject.texture = this.currentAnimation.sprites[0].texture2D;
|
||||
this._elapsedTime = 0;
|
||||
this._loopMode = loopMode ? loopMode : LoopMode.loop;
|
||||
};
|
||||
@@ -4154,7 +4178,8 @@ var es;
|
||||
};
|
||||
ComponentList.prototype.handleRemove = function (component) {
|
||||
if (component instanceof es.RenderableComponent) {
|
||||
this._entity.scene.removeChild(component.displayObject);
|
||||
if (component.displayObject.parent)
|
||||
component.displayObject.parent.removeChild(component.displayObject);
|
||||
this._entity.scene.renderableComponents.remove(component);
|
||||
}
|
||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
|
||||
@@ -4727,7 +4752,7 @@ var es;
|
||||
var component = this_1._components[i];
|
||||
var egretDisplayObject = scene.$children.find(function (a) { return a.hashCode == component.displayObject.hashCode; });
|
||||
var displayIndex = scene.getChildIndex(egretDisplayObject);
|
||||
if (displayIndex != i)
|
||||
if (displayIndex != -1 && displayIndex != i)
|
||||
scene.swapChildrenAt(displayIndex, i);
|
||||
};
|
||||
var this_1 = this;
|
||||
@@ -6384,6 +6409,45 @@ var es;
|
||||
es.Rectangle = Rectangle;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var SubpixelFloat = (function () {
|
||||
function SubpixelFloat() {
|
||||
this.remainder = 0;
|
||||
}
|
||||
SubpixelFloat.prototype.update = function (amount) {
|
||||
this.remainder += amount;
|
||||
var motion = Math.trunc(this.remainder);
|
||||
this.remainder -= motion;
|
||||
amount = motion;
|
||||
return amount;
|
||||
};
|
||||
SubpixelFloat.prototype.reset = function () {
|
||||
this.remainder = 0;
|
||||
};
|
||||
return SubpixelFloat;
|
||||
}());
|
||||
es.SubpixelFloat = SubpixelFloat;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var SubpixelVector2 = (function () {
|
||||
function SubpixelVector2() {
|
||||
this._x = new es.SubpixelFloat();
|
||||
this._y = new es.SubpixelFloat();
|
||||
}
|
||||
SubpixelVector2.prototype.update = function (amount) {
|
||||
amount.x = this._x.update(amount.x);
|
||||
amount.y = this._y.update(amount.y);
|
||||
};
|
||||
SubpixelVector2.prototype.reset = function () {
|
||||
this._x.reset();
|
||||
this._y.reset();
|
||||
};
|
||||
return SubpixelVector2;
|
||||
}());
|
||||
es.SubpixelVector2 = SubpixelVector2;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var Vector3 = (function () {
|
||||
function Vector3(x, y, z) {
|
||||
@@ -9441,7 +9505,8 @@ var es;
|
||||
ContentManager.prototype.dispose = function () {
|
||||
this.loadedAssets.forEach(function (value) {
|
||||
var assetsToRemove = value;
|
||||
assetsToRemove.dispose();
|
||||
if (RES.destroyRes(assetsToRemove))
|
||||
assetsToRemove.dispose();
|
||||
});
|
||||
this.loadedAssets.clear();
|
||||
};
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,4 +1,8 @@
|
||||
module es {
|
||||
import RenderTexture = egret.RenderTexture;
|
||||
import Bitmap = egret.Bitmap;
|
||||
import SpriteSheet = egret.SpriteSheet;
|
||||
|
||||
export class Sprite {
|
||||
public texture2D: egret.Texture;
|
||||
public readonly sourceRect: Rectangle;
|
||||
@@ -22,5 +26,37 @@ module es {
|
||||
this.uvs.width = sourceRect.width * inverseTexW;
|
||||
this.uvs.height = sourceRect.height * inverseTexH;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供一个精灵的列/行等间隔的图集的精灵列表
|
||||
* @param texture
|
||||
* @param cellWidth
|
||||
* @param cellHeight
|
||||
* @param cellOffset 处理时要包含的第一个单元格。基于0的索引
|
||||
* @param maxCellsToInclude 包含的最大单元
|
||||
*/
|
||||
public static spritesFromAtlas(texture: egret.Texture, cellWidth: number, cellHeight: number,
|
||||
cellOffset: number = 0, maxCellsToInclude: number = Number.MAX_VALUE){
|
||||
let sprites: Sprite[] = [];
|
||||
let cols = texture.textureWidth / cellWidth;
|
||||
let rows = texture.textureHeight / cellHeight;
|
||||
let i = 0;
|
||||
let spriteSheet = new SpriteSheet(texture);
|
||||
|
||||
for (let y = 0; y < rows; y ++){
|
||||
for (let x = 0; x < cols; x ++) {
|
||||
if (i++ < cellOffset) continue;
|
||||
|
||||
let texture = spriteSheet.getTexture(`${y}_${x}`);
|
||||
if (!texture)
|
||||
texture = spriteSheet.createTexture(`${y}_${x}`, x * cellWidth, y * cellHeight, cellWidth, cellHeight);
|
||||
sprites.push(new Sprite(texture));
|
||||
|
||||
if (sprites.length == maxCellsToInclude) return sprites;
|
||||
}
|
||||
}
|
||||
|
||||
return sprites;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ module es {
|
||||
this.animationState = State.completed;
|
||||
this._elapsedTime = 0;
|
||||
this.currentFrame = 0;
|
||||
this.sprite = animation.sprites[this.currentFrame];
|
||||
(this.displayObject as egret.Bitmap).texture = animation.sprites[this.currentFrame].texture2D;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ module es {
|
||||
this.currentFrame = i % n;
|
||||
}
|
||||
|
||||
this.sprite = animation.sprites[this.currentFrame];
|
||||
(this.displayObject as egret.Bitmap).texture = animation.sprites[this.currentFrame].texture2D;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,8 +123,7 @@ module es {
|
||||
this.currentAnimationName = name;
|
||||
this.currentFrame = 0;
|
||||
this.animationState = State.running;
|
||||
|
||||
this.sprite = this.currentAnimation.sprites[0];
|
||||
(this.displayObject as egret.Bitmap).texture = this.currentAnimation.sprites[0].texture2D;
|
||||
this._elapsedTime = 0;
|
||||
this._loopMode = loopMode ? loopMode : LoopMode.loop;
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ module es {
|
||||
}
|
||||
|
||||
if (this._nextScene) {
|
||||
this.removeChild(this._scene);
|
||||
if (this._scene.parent) this._scene.parent.removeChild(this._scene);
|
||||
this._scene.end();
|
||||
|
||||
this._scene = this._nextScene;
|
||||
|
||||
@@ -157,7 +157,8 @@ module es {
|
||||
public handleRemove(component: Component) {
|
||||
// 处理渲染层列表
|
||||
if (component instanceof RenderableComponent) {
|
||||
this._entity.scene.removeChild(component.displayObject);
|
||||
if (component.displayObject.parent)
|
||||
component.displayObject.parent.removeChild(component.displayObject);
|
||||
this._entity.scene.renderableComponents.remove(component);
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ module es {
|
||||
let component = this._components[i] as RenderableComponent;
|
||||
let egretDisplayObject = scene.$children.find(a => {return a.hashCode == component.displayObject.hashCode});
|
||||
let displayIndex = scene.getChildIndex(egretDisplayObject);
|
||||
if (displayIndex != i) scene.swapChildrenAt(displayIndex, i);
|
||||
if (displayIndex != -1 && displayIndex != i) scene.swapChildrenAt(displayIndex, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
module es {
|
||||
/**
|
||||
* 它存储值,直到累计的总数大于1。一旦超过1,该值将在调用update时添加到amount中
|
||||
* 一般用法如下:
|
||||
*
|
||||
* let deltaMove = this.velocity * es.Time.deltaTime;
|
||||
* deltaMove.x = this._x.update(deltaMove.x);
|
||||
* deltaMove.y = this._y.update(deltaMove.y);
|
||||
*/
|
||||
export class SubpixelFloat {
|
||||
public remainder: number = 0;
|
||||
|
||||
/**
|
||||
* 以amount递增余数,将值截断,存储新的余数并将amount设置为当前值
|
||||
* @param amount
|
||||
*/
|
||||
public update(amount: number){
|
||||
this.remainder += amount;
|
||||
let motion = Math.trunc(this.remainder);
|
||||
this.remainder -= motion;
|
||||
amount = motion;
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将余数重置为0
|
||||
*/
|
||||
public reset(){
|
||||
this.remainder = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
module es {
|
||||
export class SubpixelVector2 {
|
||||
public _x: SubpixelFloat = new SubpixelFloat();
|
||||
public _y: SubpixelFloat = new SubpixelFloat();
|
||||
|
||||
/**
|
||||
* 以数量递增s/y余数,将值截断为整数,存储新的余数并将amount设置为当前值
|
||||
* @param amount
|
||||
*/
|
||||
public update(amount: Vector2) {
|
||||
amount.x = this._x.update(amount.x);
|
||||
amount.y = this._y.update(amount.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将余数重置为0
|
||||
*/
|
||||
public reset(){
|
||||
this._x.reset();
|
||||
this._y.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,8 @@ module es {
|
||||
public dispose() {
|
||||
this.loadedAssets.forEach(value => {
|
||||
let assetsToRemove = value;
|
||||
assetsToRemove.dispose();
|
||||
if (RES.destroyRes(assetsToRemove))
|
||||
assetsToRemove.dispose();
|
||||
});
|
||||
|
||||
this.loadedAssets.clear();
|
||||
|
||||
Reference in New Issue
Block a user