新增ninja adventure例子

This commit is contained in:
YHH
2020-08-23 22:09:22 +08:00
parent 6c1cfec928
commit 7345a17d24
26 changed files with 400 additions and 27 deletions
+16
View File
@@ -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
View File
@@ -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();
};
+1 -1
View File
File diff suppressed because one or more lines are too long
+36
View File
@@ -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;
}
}
}
+3 -4
View File
@@ -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;
}
+1 -1
View File
@@ -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;
+2 -1
View File
@@ -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);
}
}
}
+32
View File
@@ -0,0 +1,32 @@
module es {
/**
* 11update时添加到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;
}
}
}
+23
View File
@@ -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();
}
}
}
+2 -1
View File
@@ -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();