[0]提供一种思路实现Camera2D 类似cocoscreator的功能
export class Camera2D extends Laya.Sprite {
private onesp:Laya.Sprite=new Laya.Sprite();
private two:Laya.Sprite = new Laya.Sprite();
private rendertarget:Laya.RenderTexture2D =new Laya.RenderTexture2D(300,300, 1, -1);
private tex:Laya.Texture;
constructor() {
super();
this.tex = Laya.Loader.getRes("res/atlas/comp.png");
this.onesp.graphics.drawTexture(this.tex,0,0,300,300);
// Laya.Stat.show();
Laya.stage.addChild(this.onesp);
this.tex =this.onesp.drawToTexture(100,100,0,0,this.rendertarget) as any;
this.two.texture = new Laya.Texture(this.tex,Laya.Texture.INV_UV);
Laya.timer.loop(10,this,this.updateCamera)
// two.graphics.drawRect(100,100,100,100,"#ff0000")
this.two.x =this.two.y =300;
Laya.stage.addChild(this.two);
}
public updateCamera(){
this.onesp.rotation+=1
// two.graphics.clear();
// texx.disposeBitmap();
var texx =this.onesp.drawToTexture(100,100,0,0,this.rendertarget) as any;
this.two.texture.bitmap =texx;
}
}
private onesp:Laya.Sprite=new Laya.Sprite();
private two:Laya.Sprite = new Laya.Sprite();
private rendertarget:Laya.RenderTexture2D =new Laya.RenderTexture2D(300,300, 1, -1);
private tex:Laya.Texture;
constructor() {
super();
this.tex = Laya.Loader.getRes("res/atlas/comp.png");
this.onesp.graphics.drawTexture(this.tex,0,0,300,300);
// Laya.Stat.show();
Laya.stage.addChild(this.onesp);
this.tex =this.onesp.drawToTexture(100,100,0,0,this.rendertarget) as any;
this.two.texture = new Laya.Texture(this.tex,Laya.Texture.INV_UV);
Laya.timer.loop(10,this,this.updateCamera)
// two.graphics.drawRect(100,100,100,100,"#ff0000")
this.two.x =this.two.y =300;
Laya.stage.addChild(this.two);
}
public updateCamera(){
this.onesp.rotation+=1
// two.graphics.clear();
// texx.disposeBitmap();
var texx =this.onesp.drawToTexture(100,100,0,0,this.rendertarget) as any;
this.two.texture.bitmap =texx;
}
}
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
Yan
赞同来自: