Merge pull request #20 from esengine/develop

实现精灵平铺效果
This commit is contained in:
YHH
2020-08-07 11:03:05 +08:00
committed by GitHub
9 changed files with 391 additions and 165 deletions
+14 -5
View File
@@ -591,12 +591,16 @@ declare module es {
} }
declare module es { declare module es {
class TiledSpriteRenderer extends SpriteRenderer { class TiledSpriteRenderer extends SpriteRenderer {
protected sourceRect: Rectangle; readonly bounds: Rectangle;
protected leftTexture: egret.Bitmap;
protected rightTexture: egret.Bitmap;
constructor(sprite: Sprite);
scrollX: number; scrollX: number;
scrollY: number; scrollY: number;
textureScale: Vector2;
width: number;
height: number;
protected _sourceRect: Rectangle;
protected _textureScale: Vector2;
protected _inverseTexScale: Vector2;
constructor(sprite: Sprite);
render(camera: es.Camera): void; render(camera: es.Camera): void;
} }
} }
@@ -604,10 +608,15 @@ declare module es {
class ScrollingSpriteRenderer extends TiledSpriteRenderer { class ScrollingSpriteRenderer extends TiledSpriteRenderer {
scrollSpeedX: number; scrollSpeedX: number;
scroolSpeedY: number; scroolSpeedY: number;
textureScale: Vector2;
scrollWidth: number;
scrollHeight: number;
private _scrollX; private _scrollX;
private _scrollY; private _scrollY;
private _scrollWidth;
private _scrollHeight;
constructor(sprite: Sprite);
update(): void; update(): void;
render(camera: Camera): void;
} }
} }
declare module es { declare module es {
+105 -43
View File
@@ -2658,6 +2658,7 @@ var es;
} }
Mesh.prototype.setTexture = function (texture) { Mesh.prototype.setTexture = function (texture) {
this._mesh.texture = texture; this._mesh.texture = texture;
this._mesh.$renderNode = new egret.sys.RenderNode();
return this; return this;
}; };
Mesh.prototype.reset = function () { Mesh.prototype.reset = function () {
@@ -2763,49 +2764,87 @@ var es;
__extends(TiledSpriteRenderer, _super); __extends(TiledSpriteRenderer, _super);
function TiledSpriteRenderer(sprite) { function TiledSpriteRenderer(sprite) {
var _this = _super.call(this, sprite) || this; var _this = _super.call(this, sprite) || this;
_this.leftTexture = new egret.Bitmap(); _this._textureScale = es.Vector2.one;
_this.rightTexture = new egret.Bitmap(); _this._inverseTexScale = es.Vector2.one;
_this.leftTexture.texture = sprite.texture2D; _this._sourceRect = sprite.sourceRect;
_this.rightTexture.texture = sprite.texture2D; var bitmap = _this.displayObject;
_this.setSprite(sprite); bitmap.$fillMode = egret.BitmapFillMode.REPEAT;
_this.sourceRect = sprite.sourceRect;
return _this; return _this;
} }
Object.defineProperty(TiledSpriteRenderer.prototype, "bounds", {
get: function () {
if (this._areBoundsDirty) {
if (this._sprite) {
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
this._areBoundsDirty = false;
}
}
return this._bounds;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TiledSpriteRenderer.prototype, "scrollX", { Object.defineProperty(TiledSpriteRenderer.prototype, "scrollX", {
get: function () { get: function () {
return this.sourceRect.x; return this._sourceRect.x;
}, },
set: function (value) { set: function (value) {
this.sourceRect.x = value; this._sourceRect.x = value;
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
Object.defineProperty(TiledSpriteRenderer.prototype, "scrollY", { Object.defineProperty(TiledSpriteRenderer.prototype, "scrollY", {
get: function () { get: function () {
return this.sourceRect.y; return this._sourceRect.y;
}, },
set: function (value) { set: function (value) {
this.sourceRect.y = value; this._sourceRect.y = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TiledSpriteRenderer.prototype, "textureScale", {
get: function () {
return this._textureScale;
},
set: function (value) {
this._textureScale = value;
this._inverseTexScale = new es.Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
this._sourceRect.width = this._sprite.sourceRect.width * this._inverseTexScale.x;
this._sourceRect.height = this._sprite.sourceRect.height * this._inverseTexScale.y;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TiledSpriteRenderer.prototype, "width", {
get: function () {
return this._sourceRect.width;
},
set: function (value) {
this._areBoundsDirty = true;
this._sourceRect.width = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TiledSpriteRenderer.prototype, "height", {
get: function () {
return this._sourceRect.height;
},
set: function (value) {
this._areBoundsDirty = true;
this._sourceRect.height = value;
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
TiledSpriteRenderer.prototype.render = function (camera) { TiledSpriteRenderer.prototype.render = function (camera) {
if (!this.sprite)
return;
_super.prototype.render.call(this, camera); _super.prototype.render.call(this, camera);
var renderTexture = new egret.RenderTexture(); var bitmap = this.displayObject;
var cacheBitmap = new egret.DisplayObjectContainer(); bitmap.width = this.width;
cacheBitmap.removeChildren(); bitmap.height = this.height;
cacheBitmap.addChild(this.leftTexture); bitmap.scrollRect = this._sourceRect;
cacheBitmap.addChild(this.rightTexture);
this.leftTexture.x = this.sourceRect.x;
this.rightTexture.x = this.sourceRect.x - this.sourceRect.width;
this.leftTexture.y = this.sourceRect.y;
this.rightTexture.y = this.sourceRect.y;
cacheBitmap.cacheAsBitmap = true;
renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
}; };
return TiledSpriteRenderer; return TiledSpriteRenderer;
}(es.SpriteRenderer)); }(es.SpriteRenderer));
@@ -2815,35 +2854,58 @@ var es;
(function (es) { (function (es) {
var ScrollingSpriteRenderer = (function (_super) { var ScrollingSpriteRenderer = (function (_super) {
__extends(ScrollingSpriteRenderer, _super); __extends(ScrollingSpriteRenderer, _super);
function ScrollingSpriteRenderer() { function ScrollingSpriteRenderer(sprite) {
var _this = _super !== null && _super.apply(this, arguments) || this; var _this = _super.call(this, sprite) || this;
_this.scrollSpeedX = 15; _this.scrollSpeedX = 15;
_this.scroolSpeedY = 0; _this.scroolSpeedY = 0;
_this._scrollX = 0; _this._scrollX = 0;
_this._scrollY = 0; _this._scrollY = 0;
_this._scrollWidth = 0;
_this._scrollHeight = 0;
_this._scrollWidth = _this.width;
_this._scrollHeight = _this.height;
return _this; return _this;
} }
Object.defineProperty(ScrollingSpriteRenderer.prototype, "textureScale", {
get: function () {
return this._textureScale;
},
set: function (value) {
this._textureScale = value;
this._inverseTexScale = new es.Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
},
enumerable: true,
configurable: true
});
Object.defineProperty(ScrollingSpriteRenderer.prototype, "scrollWidth", {
get: function () {
return this._scrollWidth;
},
set: function (value) {
this._scrollWidth = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ScrollingSpriteRenderer.prototype, "scrollHeight", {
get: function () {
return this._scrollHeight;
},
set: function (value) {
this._scrollHeight = value;
},
enumerable: true,
configurable: true
});
ScrollingSpriteRenderer.prototype.update = function () { ScrollingSpriteRenderer.prototype.update = function () {
this._scrollX += this.scrollSpeedX * es.Time.deltaTime;
this._scrollY += this.scroolSpeedY * es.Time.deltaTime;
this.sourceRect.x = this._scrollX;
this.sourceRect.y = this._scrollY;
};
ScrollingSpriteRenderer.prototype.render = function (camera) {
if (!this.sprite) if (!this.sprite)
return; return;
_super.prototype.render.call(this, camera); this._scrollX += this.scrollSpeedX * es.Time.deltaTime;
var renderTexture = new egret.RenderTexture(); this._scrollY += this.scroolSpeedY * es.Time.deltaTime;
var cacheBitmap = new egret.DisplayObjectContainer(); this._sourceRect.x = this._scrollX;
cacheBitmap.removeChildren(); this._sourceRect.y = this._scrollY;
cacheBitmap.addChild(this.leftTexture); this._sourceRect.width = this._scrollWidth + this._scrollX;
cacheBitmap.addChild(this.rightTexture); this._sourceRect.height = this._scrollHeight + this._scrollY;
this.leftTexture.x = this.sourceRect.x;
this.rightTexture.x = this.sourceRect.x - this.sourceRect.width;
this.leftTexture.y = this.sourceRect.y;
this.rightTexture.y = this.sourceRect.y;
cacheBitmap.cacheAsBitmap = true;
renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
}; };
return ScrollingSpriteRenderer; return ScrollingSpriteRenderer;
}(es.TiledSpriteRenderer)); }(es.TiledSpriteRenderer));
File diff suppressed because one or more lines are too long
+14 -5
View File
@@ -591,12 +591,16 @@ declare module es {
} }
declare module es { declare module es {
class TiledSpriteRenderer extends SpriteRenderer { class TiledSpriteRenderer extends SpriteRenderer {
protected sourceRect: Rectangle; readonly bounds: Rectangle;
protected leftTexture: egret.Bitmap;
protected rightTexture: egret.Bitmap;
constructor(sprite: Sprite);
scrollX: number; scrollX: number;
scrollY: number; scrollY: number;
textureScale: Vector2;
width: number;
height: number;
protected _sourceRect: Rectangle;
protected _textureScale: Vector2;
protected _inverseTexScale: Vector2;
constructor(sprite: Sprite);
render(camera: es.Camera): void; render(camera: es.Camera): void;
} }
} }
@@ -604,10 +608,15 @@ declare module es {
class ScrollingSpriteRenderer extends TiledSpriteRenderer { class ScrollingSpriteRenderer extends TiledSpriteRenderer {
scrollSpeedX: number; scrollSpeedX: number;
scroolSpeedY: number; scroolSpeedY: number;
textureScale: Vector2;
scrollWidth: number;
scrollHeight: number;
private _scrollX; private _scrollX;
private _scrollY; private _scrollY;
private _scrollWidth;
private _scrollHeight;
constructor(sprite: Sprite);
update(): void; update(): void;
render(camera: Camera): void;
} }
} }
declare module es { declare module es {
+105 -43
View File
@@ -2658,6 +2658,7 @@ var es;
} }
Mesh.prototype.setTexture = function (texture) { Mesh.prototype.setTexture = function (texture) {
this._mesh.texture = texture; this._mesh.texture = texture;
this._mesh.$renderNode = new egret.sys.RenderNode();
return this; return this;
}; };
Mesh.prototype.reset = function () { Mesh.prototype.reset = function () {
@@ -2763,49 +2764,87 @@ var es;
__extends(TiledSpriteRenderer, _super); __extends(TiledSpriteRenderer, _super);
function TiledSpriteRenderer(sprite) { function TiledSpriteRenderer(sprite) {
var _this = _super.call(this, sprite) || this; var _this = _super.call(this, sprite) || this;
_this.leftTexture = new egret.Bitmap(); _this._textureScale = es.Vector2.one;
_this.rightTexture = new egret.Bitmap(); _this._inverseTexScale = es.Vector2.one;
_this.leftTexture.texture = sprite.texture2D; _this._sourceRect = sprite.sourceRect;
_this.rightTexture.texture = sprite.texture2D; var bitmap = _this.displayObject;
_this.setSprite(sprite); bitmap.$fillMode = egret.BitmapFillMode.REPEAT;
_this.sourceRect = sprite.sourceRect;
return _this; return _this;
} }
Object.defineProperty(TiledSpriteRenderer.prototype, "bounds", {
get: function () {
if (this._areBoundsDirty) {
if (this._sprite) {
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
this._areBoundsDirty = false;
}
}
return this._bounds;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TiledSpriteRenderer.prototype, "scrollX", { Object.defineProperty(TiledSpriteRenderer.prototype, "scrollX", {
get: function () { get: function () {
return this.sourceRect.x; return this._sourceRect.x;
}, },
set: function (value) { set: function (value) {
this.sourceRect.x = value; this._sourceRect.x = value;
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
Object.defineProperty(TiledSpriteRenderer.prototype, "scrollY", { Object.defineProperty(TiledSpriteRenderer.prototype, "scrollY", {
get: function () { get: function () {
return this.sourceRect.y; return this._sourceRect.y;
}, },
set: function (value) { set: function (value) {
this.sourceRect.y = value; this._sourceRect.y = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TiledSpriteRenderer.prototype, "textureScale", {
get: function () {
return this._textureScale;
},
set: function (value) {
this._textureScale = value;
this._inverseTexScale = new es.Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
this._sourceRect.width = this._sprite.sourceRect.width * this._inverseTexScale.x;
this._sourceRect.height = this._sprite.sourceRect.height * this._inverseTexScale.y;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TiledSpriteRenderer.prototype, "width", {
get: function () {
return this._sourceRect.width;
},
set: function (value) {
this._areBoundsDirty = true;
this._sourceRect.width = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TiledSpriteRenderer.prototype, "height", {
get: function () {
return this._sourceRect.height;
},
set: function (value) {
this._areBoundsDirty = true;
this._sourceRect.height = value;
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
TiledSpriteRenderer.prototype.render = function (camera) { TiledSpriteRenderer.prototype.render = function (camera) {
if (!this.sprite)
return;
_super.prototype.render.call(this, camera); _super.prototype.render.call(this, camera);
var renderTexture = new egret.RenderTexture(); var bitmap = this.displayObject;
var cacheBitmap = new egret.DisplayObjectContainer(); bitmap.width = this.width;
cacheBitmap.removeChildren(); bitmap.height = this.height;
cacheBitmap.addChild(this.leftTexture); bitmap.scrollRect = this._sourceRect;
cacheBitmap.addChild(this.rightTexture);
this.leftTexture.x = this.sourceRect.x;
this.rightTexture.x = this.sourceRect.x - this.sourceRect.width;
this.leftTexture.y = this.sourceRect.y;
this.rightTexture.y = this.sourceRect.y;
cacheBitmap.cacheAsBitmap = true;
renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
}; };
return TiledSpriteRenderer; return TiledSpriteRenderer;
}(es.SpriteRenderer)); }(es.SpriteRenderer));
@@ -2815,35 +2854,58 @@ var es;
(function (es) { (function (es) {
var ScrollingSpriteRenderer = (function (_super) { var ScrollingSpriteRenderer = (function (_super) {
__extends(ScrollingSpriteRenderer, _super); __extends(ScrollingSpriteRenderer, _super);
function ScrollingSpriteRenderer() { function ScrollingSpriteRenderer(sprite) {
var _this = _super !== null && _super.apply(this, arguments) || this; var _this = _super.call(this, sprite) || this;
_this.scrollSpeedX = 15; _this.scrollSpeedX = 15;
_this.scroolSpeedY = 0; _this.scroolSpeedY = 0;
_this._scrollX = 0; _this._scrollX = 0;
_this._scrollY = 0; _this._scrollY = 0;
_this._scrollWidth = 0;
_this._scrollHeight = 0;
_this._scrollWidth = _this.width;
_this._scrollHeight = _this.height;
return _this; return _this;
} }
Object.defineProperty(ScrollingSpriteRenderer.prototype, "textureScale", {
get: function () {
return this._textureScale;
},
set: function (value) {
this._textureScale = value;
this._inverseTexScale = new es.Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
},
enumerable: true,
configurable: true
});
Object.defineProperty(ScrollingSpriteRenderer.prototype, "scrollWidth", {
get: function () {
return this._scrollWidth;
},
set: function (value) {
this._scrollWidth = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ScrollingSpriteRenderer.prototype, "scrollHeight", {
get: function () {
return this._scrollHeight;
},
set: function (value) {
this._scrollHeight = value;
},
enumerable: true,
configurable: true
});
ScrollingSpriteRenderer.prototype.update = function () { ScrollingSpriteRenderer.prototype.update = function () {
this._scrollX += this.scrollSpeedX * es.Time.deltaTime;
this._scrollY += this.scroolSpeedY * es.Time.deltaTime;
this.sourceRect.x = this._scrollX;
this.sourceRect.y = this._scrollY;
};
ScrollingSpriteRenderer.prototype.render = function (camera) {
if (!this.sprite) if (!this.sprite)
return; return;
_super.prototype.render.call(this, camera); this._scrollX += this.scrollSpeedX * es.Time.deltaTime;
var renderTexture = new egret.RenderTexture(); this._scrollY += this.scroolSpeedY * es.Time.deltaTime;
var cacheBitmap = new egret.DisplayObjectContainer(); this._sourceRect.x = this._scrollX;
cacheBitmap.removeChildren(); this._sourceRect.y = this._scrollY;
cacheBitmap.addChild(this.leftTexture); this._sourceRect.width = this._scrollWidth + this._scrollX;
cacheBitmap.addChild(this.rightTexture); this._sourceRect.height = this._scrollHeight + this._scrollY;
this.leftTexture.x = this.sourceRect.x;
this.rightTexture.x = this.sourceRect.x - this.sourceRect.width;
this.leftTexture.y = this.sourceRect.y;
this.rightTexture.y = this.sourceRect.y;
cacheBitmap.cacheAsBitmap = true;
renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
}; };
return ScrollingSpriteRenderer; return ScrollingSpriteRenderer;
}(es.TiledSpriteRenderer)); }(es.TiledSpriteRenderer));
+1 -1
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -11,6 +11,7 @@ module es {
public setTexture(texture: egret.Texture): Mesh { public setTexture(texture: egret.Texture): Mesh {
this._mesh.texture = texture; this._mesh.texture = texture;
this._mesh.$renderNode = new egret.sys.RenderNode();
return this; return this;
} }
@@ -1,37 +1,67 @@
///<reference path="./TiledSpriteRenderer.ts"/> ///<reference path="./TiledSpriteRenderer.ts"/>
module es { module es {
export class ScrollingSpriteRenderer extends TiledSpriteRenderer { import Bitmap = egret.Bitmap;
public scrollSpeedX = 15;
public scroolSpeedY = 0;
private _scrollX = 0;
private _scrollY = 0;
public update() { export class ScrollingSpriteRenderer extends TiledSpriteRenderer {
this._scrollX += this.scrollSpeedX * Time.deltaTime; /**
this._scrollY += this.scroolSpeedY * Time.deltaTime; * x自动滚动速度(/s为单位)
this.sourceRect.x = this._scrollX; */
this.sourceRect.y = this._scrollY; public scrollSpeedX = 15;
/**
* y速度(/s为单位)
*/
public scroolSpeedY = 0;
public get textureScale(): Vector2 {
return this._textureScale;
} }
public render(camera: Camera) { public set textureScale(value: Vector2){
this._textureScale = value;
// 重新计算我们的inverseTextureScale和源矩形大小
this._inverseTexScale = new Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
}
public set scrollWidth(value: number){
this._scrollWidth = value;
}
public get scrollWidth(){
return this._scrollWidth;
}
public set scrollHeight(value: number){
this._scrollHeight = value;
}
public get scrollHeight(){
return this._scrollHeight;
}
private _scrollX = 0;
private _scrollY = 0;
private _scrollWidth = 0;
private _scrollHeight = 0;
constructor(sprite: Sprite) {
super(sprite);
this._scrollWidth = this.width;
this._scrollHeight = this.height;
}
public update() {
if (!this.sprite) if (!this.sprite)
return; return;
super.render(camera); this._scrollX += this.scrollSpeedX * Time.deltaTime;
this._scrollY += this.scroolSpeedY * Time.deltaTime;
let renderTexture = new egret.RenderTexture(); this._sourceRect.x = this._scrollX;
let cacheBitmap = new egret.DisplayObjectContainer(); this._sourceRect.y = this._scrollY;
cacheBitmap.removeChildren(); this._sourceRect.width = this._scrollWidth + this._scrollX;
cacheBitmap.addChild(this.leftTexture); this._sourceRect.height = this._scrollHeight + this._scrollY;
cacheBitmap.addChild(this.rightTexture);
this.leftTexture.x = this.sourceRect.x;
this.rightTexture.x = this.sourceRect.x - this.sourceRect.width;
this.leftTexture.y = this.sourceRect.y;
this.rightTexture.y = this.sourceRect.y;
cacheBitmap.cacheAsBitmap = true;
renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
} }
} }
} }
@@ -1,60 +1,113 @@
///<reference path="./SpriteRenderer.ts" /> ///<reference path="./SpriteRenderer.ts" />
module es { module es {
import Bitmap = egret.Bitmap;
/** /**
* *
*/ */
export class TiledSpriteRenderer extends SpriteRenderer { export class TiledSpriteRenderer extends SpriteRenderer {
protected sourceRect: Rectangle; public get bounds(): Rectangle {
protected leftTexture: egret.Bitmap; if (this._areBoundsDirty){
protected rightTexture: egret.Bitmap; if (this._sprite){
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin,
this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
this._areBoundsDirty = false;
}
}
return this._bounds;
}
/**
* x值
*/
public get scrollX() {
return this._sourceRect.x;
}
/**
* x值
* @param value
*/
public set scrollX(value: number) {
this._sourceRect.x = value;
}
/**
* y值
*/
public get scrollY() {
return this._sourceRect.y;
}
/**
* y值
* @param value
*/
public set scrollY(value: number) {
this._sourceRect.y = value;
}
/**
*
*/
public get textureScale(): Vector2 {
return this._textureScale;
}
/**
*
* @param value
*/
public set textureScale(value: Vector2) {
this._textureScale = value;
// 重新计算我们的inverseTextureScale和源矩形大小
this._inverseTexScale = new Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
this._sourceRect.width = this._sprite.sourceRect.width * this._inverseTexScale.x;
this._sourceRect.height = this._sprite.sourceRect.height * this._inverseTexScale.y;
}
/**
* TiledSprite可以有一个独立于其纹理的宽度
*/
public get width(): number{
return this._sourceRect.width;
}
public set width(value: number) {
this._areBoundsDirty = true;
this._sourceRect.width = value;
}
public get height(): number {
return this._sourceRect.height;
}
public set height(value: number) {
this._areBoundsDirty = true;
this._sourceRect.height = value;
}
protected _sourceRect: Rectangle;
protected _textureScale = Vector2.one;
protected _inverseTexScale = Vector2.one;
constructor(sprite: Sprite) { constructor(sprite: Sprite) {
super(sprite); super(sprite);
this.leftTexture = new egret.Bitmap(); this._sourceRect = sprite.sourceRect;
this.rightTexture = new egret.Bitmap(); let bitmap = this.displayObject as Bitmap;
this.leftTexture.texture = sprite.texture2D; bitmap.$fillMode = egret.BitmapFillMode.REPEAT;
this.rightTexture.texture = sprite.texture2D;
this.setSprite(sprite);
this.sourceRect = sprite.sourceRect;
}
public get scrollX() {
return this.sourceRect.x;
}
public set scrollX(value: number) {
this.sourceRect.x = value;
}
public get scrollY() {
return this.sourceRect.y;
}
public set scrollY(value: number) {
this.sourceRect.y = value;
} }
public render(camera: es.Camera) { public render(camera: es.Camera) {
if (!this.sprite)
return;
super.render(camera); super.render(camera);
let renderTexture = new egret.RenderTexture(); let bitmap = this.displayObject as Bitmap;
let cacheBitmap = new egret.DisplayObjectContainer(); bitmap.width = this.width;
cacheBitmap.removeChildren(); bitmap.height = this.height;
cacheBitmap.addChild(this.leftTexture); bitmap.scrollRect = this._sourceRect;
cacheBitmap.addChild(this.rightTexture);
this.leftTexture.x = this.sourceRect.x;
this.rightTexture.x = this.sourceRect.x - this.sourceRect.width;
this.leftTexture.y = this.sourceRect.y;
this.rightTexture.y = this.sourceRect.y;
cacheBitmap.cacheAsBitmap = true;
renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
} }
} }
} }