[]Laya.loader.load 教程代码出错
package {
import laya.display.Text;
import laya.display.Sprite;
import laya.utils.Handler;
import laya.resource.Texture;
public class LayaSample {
private var img:Sprite ;
private var index:int ;
public function LayaSample() {
//初始化引擎
Laya.init(600, 300);
img = new Sprite();
var arr:Array = [];
for (index=0;index <=31;index++)
{
var url:String = "../Res/Images/Role1/00011208_"+ index.toString() +".bmp";
arr.push(url);
}
Laya.loader.load(arr,Handler.create(this,LoadComplated));
}
private function LoadComplated(e:*=null):void
{
Laya.stage.addChild(img);
img.on("click",this,OnImgClick);
OnImgClick();
var txt:Text = new Text();
txt.text = "loadcomplated!";
Laya.stage.addChild(txt);
}
private function OnImgClick(e:*=null):void
{
if ( ++index > 31)
{
index = 0;
}
var url:String = "../Res/Images/Role1/00011208_"+ index.toString() +".bmp";
img.graphics.clear();
var txture:Texture = Laya.loader.getRes(url);
img.graphics.drawTexture(txture);
img.size(txture.width,txture.height);
}
}
}
运行后在 LayaSample.max.js 692行提示异常
if (!tex.loaded){
tex.once("loaded",this,this._textureLoaded,[tex,args]);
编辑了好几次,这个代码的功能似乎有点问题。
代码现在是这个yang样子的:
public function LayaSample() {
//初始化引擎
Laya.init(600, 300);
img = new Sprite();
Laya.loader.load("Res/Images/Role1/00011208_0.bmp",Handler.create(this,loadComplated));
}
private function loadComplated():void
{
var txt:Text = new Text();
txt.text = "loadcomplated!";
Laya.stage.addChild(txt);
img.graphics.clear();
var txture:Texture = Laya.loader.getRes("Res/Images/Role1/00011208_0.bmp");
img.graphics.drawTexture(txture);
Laya.stage.addChild(img);
}
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
cqgcs
赞同来自:
Monica - 知识达人
赞同来自:
还是不可以的话麻烦上传一个可以运行的Demo(不要直接贴代码),我们看下!