color问题,不知道是引擎bug,还是写法问题

最近在完成个小项目,目的是将机器人碎片组合起来(拼图),碎片是一张机器人整图通过cc.rect切开的,一共切成了0-8块碎片。想达到一个功能就是当碎片移动到正确的组装位置时,碎片显示绿色。
郁闷的事情来了,当碎片移动到正确的组装位置后,都会显示绿色,但是1-8碎片切图都会自动变成第0块切图。。。求解,谢谢!
使用的cocos2d-js-v3.7.js引擎
附上源码:
//切片源码
var xj= 0,yj=0;
for(var i=0;i<9;i++){
xj=Math.floor(i/3);
yj=yj>=3?0:yj;
this.robot*=new robotUnit(res.robot,cc.rect(yj170,xj170,170,170));
this.robot*.attr({
x:size.width/4+85yj,
y:size.height/2.5+85
(2-xj),
anchorX:0.5,
anchorY:0.5,
scale:0.5,
rid:i,
x1:size.width/4+85yj,
y1:size.height/2.5+85
(2-xj),
msg:msg*
});

        this.addChild(this.robot*,3);

        yj++;
    }

//机器人碎片类
//robotUnit
var robotUnit=cc.Sprite.extend({
rid:0,
x1:0,
y1:0,
msg:’’,
onEnter:function(){
this._super();
},
goRotate:function(route){
var actionBy = cc.rotateBy(3, 360).repeatForever();
this.runAction(actionBy);
this.runAction(route);
cc.eventManager.addListener(listener1.clone(),this);
},

stopRotate:function(){
    this.stopAllActions();

}

});

//touch移动事件
var listener1=cc.EventListener.create({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches: true,
onTouchBegan: function (touch, event) {
var target = event.getCurrentTarget();

    var locationInNode = target.convertToNodeSpace(touch.getLocation());
    var s = target.getContentSize();
    var rect = cc.rect(0, 0, s.width, s.height);

    if (cc.rectContainsPoint(rect, locationInNode)) {
        target.stopRotate();
        target.opacity = 180;
        return true;
    }
    return false;
},
onTouchMoved: function (touch, event) {
    var target = event.getCurrentTarget();
    var delta = touch.getDelta();
    target.x += delta.x;
    target.y += delta.y;

    if(target.x<=(target.x1+50) && target.x>=(target.x1-50) && target.y<=(target.y1+50) && target.y>=(target.y1-50)){
        target.color=cc.color.GREEN;//问题所在,设置后1-8块碎片图案全部变为第0个碎片图案了
    }else{
        target.color=cc.color.WHITE;
    }
},
onTouchEnded: function (touch, event) {
    var target = event.getCurrentTarget();
    target.setOpacity(255);
    target.color=cc.color.WHITE;
    if(target.x<=(target.x1+50) && target.x>=(target.x1-50) && target.y<=(target.y1+50) && target.y>=(target.y1-50)){
        target.stopRotate();
        target.runAction(cc.rotateTo(0, 0));
        target.x=target.x1;
        target.y=target.y1;
    }else{
        target.goRotate();
    }

}

});****

如果楼主问题还没解决的话,麻烦把注释写的稍微详细一些

你用的事件克隆?你试试是不是这个原因

1.你设置的是target 的 color 其他图片怎么会变 你确定是这句引起的?
2.如果是 你跟踪一下target对象 看是不是你点击的那个对象。
3. this.runAction(route); 你代码中的这句是干什么用的 ,根据你的代码 传进来的route是undefined吧

好的,一会我补一个说明

我试过不克隆,随便哪个图片依然会跳回第一个切图

1、非常确定,如果我注释了target.color=cc.color.GREEN;这段,就不会有问题了
2、taiget是我点击的那个对象,我已测试了
3、 this.runAction(route);route是个随机路线值

/**

  • 这是一个拼图游戏,做的方法是将一幅图打碎成9块碎片(编号0-8),当用户晃动手机后,碎片自动飞往各处。用户将碎片移动到原本的位置后,拼图完成。
    *原本想法是碎片移动到原来的位置后,碎片显示绿色,现在只要设置碎片为绿色后,编号为1-8的碎片切图全部变为了0号碎片图。
    */

var sayingLable,detailLabel,lookLabel,heart,contentLabel;
var fireHeart =cc.ParticleFire.extend({//火离子效果
_listener: null,
ctor: function() {
this._super();
return true;
},
onEnter: function() {
this._super();
//监听器

    this._listener = new cc.EventListener.create({
        event: cc.EventListener.TOUCH_ONE_BY_ONE,
        swallowTouches: false,
        _openWin:0,
        onTouchBegan: function(touch, event){
            if(this._openWin==1){
                contentLabel.setVisible(true);
                this._openWin=0;
            }
            this.setSwallowTouches(false);
            return true;
        }
    });
    //添加触摸监听
    cc.eventManager.addListener(this._listener, this);
},
show:function(){
    this.setVisible(true);
    this._listener._openWin=1;
    this._listener.setSwallowTouches(true);
}

});

var PlayLayer=cc.Layer.extend({
robot:new Array(9),
ctor:function(){
this._super();
var size=cc.winSize;
this.bgSprite=new cc.Sprite(res.bg_2);
this.bgSprite.attr({
x:size.width/2,
y:size.height/1.5,
scale:0.3
}
);
this.addChild(this.bgSprite,0);

    this.dottedline=new cc.Sprite(res.line);
    this.dottedline.attr({
            x:size.width/2,
            y:size.height/1.75,
            scale:0.17,
            opacity:100
        }
    );
    this.addChild(this.dottedline,2);

    //===
    contentLabel=new cc.Sprite(res.content);
    contentLabel.attr({
            x:size.width/2,
            y:size.height/2.5,
            visible:false

        }
    );
    var contentTit=new cc.LabelTTF('OneNet 平台介绍','Arial',18);
    contentTit.setPosition(cc.p(150, 295));
    contentLabel.addChild(contentTit);

    var contentDetail=new cc.LabelTTF('新浪体育讯\n   北京时间8月14日,据ESPN报道,\n尽管勒布朗-詹姆斯对骑士队管理层在今夏\n的运作表示称赞,但是他强调球队需要\n尽快续约受限自由球员特里斯坦-汤普森。\n   “我们现在的首要目标就是签下特里斯坦。”\n詹姆斯在今天出席公开活动时说道,\n“他是我们球队里的一个重要组成部分。\n无论是短期还是长期,\n他都能使我们球队变得更有威胁。','Arial',14);
    contentDetail.setAnchorPoint(0,0.6);
    contentDetail.setPosition(cc.p(10, 195));
    contentLabel.addChild(contentDetail);

    var butLabel = new cc.LabelTTF("分享并连接未来", "Arial", 20);
    var butMenuItem = new cc.MenuItemLabel(butLabel, this._shareVisit, this);
    butMenuItem.setPosition(cc.p(150,15));
    var menu = new cc.Menu(butMenuItem);
    menu.setPosition(cc.p(0, 0));
    contentLabel.addChild(menu);

    this.addChild(contentLabel,8);
    //===
    var msg=new Array(9);
    msg='0';
    msg='1';
    msg='2';
    msg='3';
    msg='4';
    msg='5';
    msg='6';
    msg='7';
    msg='8';

    var xj= 0,yj=0;
    for(var i=0;i<9;i++){
        xj=Math.floor(i/3);
        yj=yj>=3?0:yj;
        this.robot*=new robotUnit(res.robot,cc.rect(yj*170,xj*170,170,170));
        this.robot*.attr({
            x:size.width/4+85*yj,
            y:size.height/2.5+85*(2-xj),
            anchorX:0.5,
            anchorY:0.5,
            scale:0.5,
            rid:i,
            x1:size.width/4+85*yj,
            y1:size.height/2.5+85*(2-xj),
            msg:msg*
        });

        this.addChild(this.robot*,3);

        yj++;
    }

    this.sayingLable=new cc.LabelTTF('摇晃手机,帮助Dr.He找到零件!','Arial',16);
    sayingLable=this.sayingLable;
    this.sayingLable.attr({
        x:size.width/2,
        y:size.height/5

    });
    //this.sayingLable.setColor(cc.color(255,0,0));
    this.addChild(this.sayingLable,2);

    detailLabel=new cc.LabelTTF('物联网开放平台领航者,\n为你的生活和工作加速!','Arial',14);
    detailLabel.attr({
        x:size.width/2,
        y:size.height/7,
        visible:false

    });
    detailLabel.setColor(cc.color(255,0,0));
    this.addChild(detailLabel,5);

    lookLabel=new cc.LabelTTF('——看看我的内心世界','Arial',12);
    lookLabel.attr({
        x:size.width/1.3,
        y:size.height/1.5,
        visible:false

    });
    lookLabel.setColor(cc.color(255,0,0));
    this.addChild(lookLabel,5);

    //火焰心
    heart = new fireHeart();
    heart.attr({
        x:size.width/1.85,
        y:size.height/1.5,
        scale:0.2,
        visible:false

    });
    this.addChild(heart,5);

    //弹窗展示

    //////
    this.shake=0;
    var theLayer=this;
    //if('keyboard' in cc.sys.capabilities){
    //    cc.eventManager.addListener({
    //        event:cc.EventListener.KEYBOARD,
    //        onKeyPressed:function(k,event){
    //            if(theLayer.shake>0){return false;}
    //            moveRoute.init();
    //            for(var i=0;i<9;i++){
    //                theLayer.robot*.goRotate(moveRoute.getRoute(i));
    //
    //            }
    //            theLayer.sayingLable.setString('请拖动身体部件拼装OneNet');
    //            theLayer.shake=1;
    //        }
    //    },this);
    //}
    if('accelerometer' in cc.sys.capabilities){
        cc.inputManager.setAccelerometerInterval(1/30);
        cc.inputManager.setAccelerometerEnabled(true);
        cc.eventManager.addListener({
            event:cc.EventListener.ACCELERATION,
            callback: function(accelEvent, event){
                if(accelEvent.x<0.2 || accelEvent.y<0.2 ){return false;}
                if(theLayer.shake>0){return false;}
                moveRoute.init();
                for(var i=0;i<9;i++){
                    theLayer.robot*.goRotate(moveRoute.getRoute(i));

                }
                theLayer.sayingLable.setString('请拖动身体部件拼装OneNet');
                theLayer.shake=1;

            }
        }, this);
    }

},
_shareVisit:function(){
    window.open('http://cq.sina.com.cn');
}

});

var dLayer;

var PlayScene=cc.Scene.extend({

onEnter:function(){
    this._super();
    var winSize = cc.winSize;
    dLayer=new ModalDialogueBox();
    dLayer.attr({
        x:winSize.width/2,
        y:winSize.height/2
    });
    this.addChild(dLayer,10);


    var layer=new PlayLayer();
    this.addChild(layer,0);


}

});

//robotUnit
var robotUnit=cc.Sprite.extend({
rid:0,
x1:0,
y1:0,
msg:’’,
onEnter:function(){
this._super();
},
goRotate:function(route){
var actionBy = cc.rotateBy(3, 360).repeatForever();
this.runAction(actionBy);
this.runAction(route);
this.rListener=listener1.clone();
cc.eventManager.addListener(this.rListener,this);
},

stopRotate:function(){
    this.stopAllActions();
},
stopMove:function(){
    cc.eventManager.removeListener(this.rListener);
}

});
var overUnit=0;
var listener1=cc.EventListener.create({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches: true,
onTouchBegan: function (touch, event) {
var target = event.getCurrentTarget();

    var locationInNode = target.convertToNodeSpace(touch.getLocation());
    var s = target.getContentSize();
    var rect = cc.rect(0, 0, s.width, s.height);

    if (cc.rectContainsPoint(rect, locationInNode)) {
        target.stopRotate();
        target.opacity = 180;
        return true;
    }
    return false;
},
onTouchMoved: function (touch, event) {
    var target = event.getCurrentTarget();
    var delta = touch.getDelta();
    target.x += delta.x;
    target.y += delta.y;

    if(target.x<=(target.x1+50) && target.x>=(target.x1-50) && target.y<=(target.y1+50) && target.y>=(target.y1-50)){
        //target.color=cc.color.GREEN;//问题所在,设置后1-8块碎片图案全部变为第0个碎片图案了
        target.opacity = 255;
    }else{
        target.opacity = 180;
    }
},
onTouchEnded: function (touch, event) {
    var target = event.getCurrentTarget();
    target.setOpacity(255);
    target.color=cc.color.WHITE;
    if(target.x<=(target.x1+50) && target.x>=(target.x1-50) && target.y<=(target.y1+50) && target.y>=(target.y1-50)){
        target.stopRotate();
        target.runAction(cc.rotateTo(0, 0));
        target.x=target.x1;
        target.y=target.y1;
        target.stopMove();
        overUnit+=1;

        if(overUnit<9){

            dLayer.alert(target.msg);
        }else{
            dLayer.butLabel.setString('组装完成!');
            dLayer.alert(target.msg);
            sayingLable.setString('我是OneNet机器人!');
            detailLabel.setVisible(true);
            lookLabel.setVisible(true);
            heart.show();
        }
    }else{
        target.goRotate();
    }

}

});

//move route
var moveRoute={
routeArr:new Array(13),
init:function () {
var s = cc.winSize;
this.routeArr=cc.moveTo(1, cc.p(s.width/6, s.height/8));
this.routeArr=cc.moveTo(1, cc.p(s.width/6, s.height/3));
this.routeArr=cc.moveTo(1, cc.p(s.width/6, s.height/2));
this.routeArr=cc.moveTo(1, cc.p(s.width/6, s.height/1.5));
this.routeArr=cc.moveTo(1, cc.p(s.width/6, s.height/1.1));
this.routeArr=cc.moveTo(1, cc.p(s.width/1.5, s.height/8));
this.routeArr=cc.moveTo(1, cc.p(s.width/1.1, s.height/8));
this.routeArr=cc.moveTo(1, cc.p(s.width/1.1, s.height/3));
this.routeArr=cc.moveTo(1, cc.p(s.width/1.1, s.height/2));
this.routeArr=cc.moveTo(1, cc.p(s.width/1.1, s.height/1.5));
this.routeArr=cc.moveTo(1, cc.p(s.width/1.1, s.height/1.1));
this.routeArr=cc.moveTo(1, cc.p(s.width/1.5, s.height/1.1));
this.routeArr=cc.moveTo(1, cc.p(s.width/1.1, s.height/1.1));
this.routeArr.sort(function(){return Math.random()>0.5?-1:1;});
},
getRoute:function(i){
return this.routeArr*.clone();
}

};

//dialog
var ModalDialogueBox = cc.LayerColor.extend({
_listener: null,
ctor: function() {

    this._super(cc.color.BLACK);
    this.ignoreAnchorPointForPosition(false);   //忽略锚点设置为false,默认为true,锚点(0, 0)

    this.setOpacity(128);       //透明度

    //初始化对话框
    this._initDialog();

    return true;
},

onEnter: function()
{
    this._super();
    //监听器

    this._listener = new cc.EventListener.create({
        event: cc.EventListener.TOUCH_ONE_BY_ONE,
        swallowTouches: false,
        onTouchBegan: function(touch, event)
        {
            return true;
        }
    });

    //添加触摸监听
    cc.eventManager.addListener(this._listener, this);

},
//初始化对话框
_initDialog: function()
{
    var winSize = cc.winSize;

    //背景
    var bg = new cc.Sprite(res.dialog);
    bg.setPosition(cc.p(winSize.width/2 , winSize.height/2));

    this.addChild(bg,0,101);

    this.dContent=new cc.LabelTTF("", "Arial", 20);
    this.dContent.attr({
        x:280,
        y:80,
        width:winSize.width/1.5,
        height:winSize.height/10,
        color:cc.color(180,180,180)
    });
    bg.addChild(this.dContent);
    //OK按钮
    //var OKLabel = new cc.LabelTTF("OK", "Arial", 25);
    //var OKMenuItem = new cc.MenuItemLabel(OKLabel, this._onCallback, this);
    //OKMenuItem.setPosition(cc.p(50, 40));

    ////Cancel按钮
    //var cancelLabel = new cc.LabelTTF("Cancel", "Arial", 25);
    //var cancelMenuItem = new cc.MenuItemLabel(cancelLabel, this._onCallback, this);
    //cancelMenuItem.setPosition(cc.p(150, 40));
    //菜单
    //var menu = new cc.Menu(OKMenuItem, cancelMenuItem);

    this.butLabel = new cc.LabelTTF("继续拼装", "Arial", 25);
    var butMenuItem = new cc.MenuItemLabel(this.butLabel, this._onCallback, this);
    butMenuItem.setPosition(cc.p(75, 40));

    var menu = new cc.Menu(butMenuItem);

    menu.setPosition(cc.p(0, 0));
    bg.addChild(menu);      //注意是添加到背景里面

    this.setVisible(false);     //默认设置为不可见

},

_onCallback: function()
{
    this.hidden();
},

//弹出
alert: function(str)
{
    this.dContent.setString(str);
    this.setVisible(true);
    this._listener.setSwallowTouches(true);
    var bg = this.getChildByTag(101);
    bg.setScale(0);
    var scaleTo = new cc.ScaleTo(0.5, 0.5);
    var rotateBy = new cc.RotateBy(0.5, 360, 0);
    var spawn = new cc.Spawn(scaleTo, rotateBy);
    bg.runAction(spawn);
},

//隐藏
hidden: function()
{
    this.setVisible(false);
    this._listener.setSwallowTouches(false);
},

onExit: function()
{
    this._super();
    //移除触摸监听
    cc.eventManager.removeListeners(cc.EventListener.TOUCH_ONE_BY_ONE, true);
}

});*******

顶一下,希望有同学来帮助