[]在父sprite中添加子sprite ,移动父Sprite 子sprite为什么不动?

(function(){
// 配置数据
var data = configJSON;
// 目标等级
var target = {
"tower":{"level":1},
"aeroboat":{"level":1},
"mountain":{"level":1},
"statue":{"level":1},
"angel":{"level":1}
};
var towerLel = target.tower.level;
var aeroboatLel = target.aeroboat.level;
var mountainLel = target.mountain.level;
var statueLel = target.statue.level;
var angelLel = target.angel.level;
// 构造
function IsLand() {
// 初始化
IsLand.__super.call(this);
// 名字
this.name = "gemini";
this.init();
}
// 注册类 IsLand
Laya.class(IsLand,"IsLand",laya.display.Sprite);
// 原型
var _proto = IsLand.prototype;
// 初始化
_proto.init = function(){
// 球体
this.ball = new Sprite();
// 城堡
this.tower = new Sprite();
// 飞艇
this.aeroboat = new Sprite();
// 山
this.mountain = new Sprite();
// 雕像
this.statue = new Sprite();
// 守护神
this.angel = new Sprite();

// 加载主体的背景
Laya.loader.load("res/island.png", Handler.create(this, function()
{
// 图片加载
var t = Laya.loader.getRes("res/island.png");

var tBall = Texture.create(t,866,190,548,305);
var tTower = Texture.create(t,data.tower[towerLel].x,data.tower[towerLel].y,data.tower[towerLel].w,data.tower[towerLel].h);
var tAeroboat = Texture.create(t,data.aeroboat[aeroboatLel].x , data.aeroboat[aeroboatLel].y, data.aeroboat[aeroboatLel].w , data.aeroboat[aeroboatLel].h);
var tMountain = Texture.create(t,data.mountain[mountainLel].x , data.mountain[mountainLel].y, data.mountain[mountainLel].w , data.mountain[mountainLel].h);
var tStatue = Texture.create(t,data.statue[statueLel].x , data.statue[statueLel].y, data.statue[statueLel].w , data.statue[statueLel].h);
var tAngel = Texture.create(t,data.angel[angelLel].x , data.angel[angelLel].y, data.angel[angelLel].w , data.angel[angelLel].h);

this.ball.graphics.drawTexture(tBall, 0,0,548,305);
this.tower.graphics.drawTexture(tTower, 0, 0, data.tower[towerLel].w , data.tower[towerLel].h);
this.aeroboat.graphics.drawTexture(tAeroboat,0,0, data.aeroboat.w, data.aeroboat.h);
this.mountain.graphics.drawTexture(tMountain,0,0, data.mountain.w, data.mountain.h);
this.statue.graphics.drawTexture(tStatue,0,0, data.statue[statueLel].w, data.statue[statueLel].h);
this.angel.graphics.drawTexture(tAngel,0,0, data.angel[angelLel].w, data.angel[angelLel].h);

// 球体和城堡的矩形显示区域
var boundBall = this.ball.getBounds();
var boundTower = this.tower.getBounds();
var boundAeroboat = this.aeroboat.getBounds();
var boundMountain = this.mountain.getBounds();
var boundStatue = this.statue.getBounds();
var boundAngel = this.angel.getBounds();

// 设置位置
this.pos(42,399);
this.tower.pos((boundBall.width - boundTower.width)/2+data.tower[towerLel].c1, -data.tower[towerLel].h+data.tower[towerLel].c2);
this.aeroboat.pos((boundBall.width - boundTower.width)/2+data.tower[towerLel].c1 - 2*boundAeroboat.width/3 ,-data.tower[towerLel].h+data.tower[towerLel].c2);
this.mountain.pos((boundBall.width - boundMountain.width)/2+data.mountain[mountainLel].c1,-data.mountain[mountainLel].h+data.mountain[mountainLel].c2);
this.statue.pos(data.statue[statueLel].c1 ,data.statue[statueLel].c2);
this.angel.pos(data.angel[angelLel].c1 ,data.angel[angelLel].c2);

// 雕塑加一个发光滤镜(webgl不支持),设置滤镜集合
// var glowFilter = new GlowFilter("#ffff00", 5, 0, 0);
// this.statue.filters = [glowFilter];

// 守护神设置旋转
this.angel.pivot(boundAngel.width/2,boundAngel.height);
this.angel.rotation = -15;

// 守护神设置呼吸
Laya.Tween.to(this.angel,{scaleY:0.99},900,Laya.Ease.linearInOut,Handler.create(this,this.angelTween1));

// 飞艇设置浮动
Laya.Tween.to(this.aeroboat,{y:-data.aeroboat[aeroboatLel].h-8},800,Laya.Ease.linearInOut,Handler.create(this,this.aeroboatTween1));

}));


this.addChild(this.mountain);
this.addChild(this.aeroboat);
this.addChild(this.tower);
this.addChild(this.ball);
this.addChild(this.statue);
this.addChild(this.angel);
}
// 更新岛
_proto.update = function(target){
var obj = {};
// 解析target
switch (target.type) {
case 1:
obj.type = "mountain";
break;
case 2:
obj.type = "statue";
break;
case 3:
obj.type = "tower";
break;
case 4:
obj.type = "angel";
break;
case 5:
obj.type = "aeroboat";
break;
default:
alert("网络连接错误,请重新进入游戏~");
break;
}
obj.lel = target.lel;

// 加载主体的背景
Laya.loader.load("res/island.png", Handler.create(this, function()
{
// 图片加载
var t = Laya.loader.getRes("res/island.png");

var tObj = Texture.create(t,data[obj.type][obj.lel].x, data[obj.type][obj.lel].y, data[obj.type][obj.lel].w, data[obj.type][obj.lel].h);

this[obj.type].graphics.clear();

this[obj.type].graphics.drawTexture(tObj, 0, 0, data[obj.type][obj.lel].w , data[obj.type][obj.lel].h);

// 球体和目标精灵的矩形显示区域
var boundBall = this.ball.getBounds();
var boundTower = this.tower.getBounds();
var boundObj = this[obj.type].getBounds();

// 设置位置
switch (obj.type) {
case "tower":
this[obj.type].pos((boundBall.width - boundObj.width)/2+data.tower[obj.lel].c1, -data.tower[obj.lel].h+data.tower[obj.lel].c2);
break;
case "aeroboat":
this[obj.type].pos((boundBall.width - boundTower.width)/2+data.tower[obj.lel].c1 - 2*boundAeroboat.width/3 ,-data.tower[obj.lel].h+data.tower[obj.lel].c2);
break;
case "mountain":
this[obj.type].pos((boundBall.width - boundObj.width)/2+data.mountain[obj.lel].c1,-data.mountain[obj.lel].h+data.mountain[obj.lel].c2);
break;
case "statue":
this[obj.type].pos(data.statue[obj.lel].c1 ,data.statue[obj.lel].c2);
break;
case "angel":
this[obj.type].pos(data.angel[obj.lel].c1 ,data.angel[obj.lel].c2);
break;
default:
break;
}
}));
}
// 移动
_proto.move = function(x,y){

// this.x = x;
// this.y = y;
// this.visible =true;
this.render();
this.mountain.pos(x,y);
this.aeroboat.x = x;
this.aeroboat.y = y;
this.tower.x = x;
this.tower.y = y;
this.ball.x = x;
this.ball.y = y;
this.statue.x = x;
this.statue.y = y;
this.angel.x = x;
this.angel.y = y;
this.clear;
// this.init();
}
// 飞艇缓动(浮动)
_proto.aeroboatTween1 = function(){
// 用一个变量不断递归循环,来计算循环的次数,根据循环次数做处理
// num++;
// trace(num);
Laya.Tween.clearTween(this.aeroboatTween1);
Laya.Tween.to(this.aeroboat,{y:-data.aeroboat[aeroboatLel].h-12},800,Laya.Ease.linearInOut,Handler.create(this,this.aeroboatTween2));
}
_proto.aeroboatTween2 = function(){
Laya.Tween.clearTween(this.aeroboatTween2);
Laya.Tween.to(this.aeroboat,{y:-data.aeroboat[aeroboatLel].h-8},800,Laya.Ease.linearInOut,Handler.create(this,this.aeroboatTween1));
}
// 守护神缓动(呼吸)
_proto.angelTween1 = function(){
Laya.Tween.clearTween(this.angelTween1);
Laya.Tween.to(this.angel,{scaleY:1},900,Laya.Ease.linearInOut,Handler.create(this,this.angelTween2));
}
_proto.angelTween2 = function(){
Laya.Tween.clearTween(this.angelTween2);
Laya.Tween.to(this.angel,{scaleY:0.99},900,Laya.Ease.linearInOut,Handler.create(this,this.angelTween1));
}
})();

调用
// 创建岛屿
this.island = new IsLand();
// 岛屿添加到舞台
Laya.stage.addChild(this.island);
this.island.autoSize = true;
this.island.move(100,100);
没有一起移动
已邀请:

tumiLeo

赞同来自:

问题解决了 ,是因为我把父sprite的pos()放到
Laya.loader.load里面了,为什么不能这么放了?@ALL

Monica - 知识达人

赞同来自:

麻烦上传一个能运行的Demo吧,我们看下

该问题目前已经被锁定, 无法添加新回复

商务合作
商务合作