新增ninja adventure例子
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user