[]克隆sprite

什么克隆一个对象啊?  在下面的“   tempSpr2.graphics.drawTexture(tempSpr.texture, 0, 0, tempSpr.width, tempSpr.height);”中 tempSpr.texture 是空的
if (data && data.items != []) {
            let tempSpr: Sprite = new Sprite();
            let tempImg: Laya.Image;
            let arr: Array<object> = <Array<object>>data.items;
            let element: any;
            let maxY: number = 0 | 0;
            for (let i: number = 0; i < arr.length; i++) {
                element = arr[i];
                if (element) {
                    tempImg = new Laya.Image(GameResPath.mapPath + this.currMapID + "/" + element.src);

                    tempImg.x = element.x;
                    tempImg.y = element.y;
                    if (maxY < element.y) {
                        maxY = element.y;
                    }
                }
                tempImg.y = maxY;
                tempSpr.addChild(tempImg);
            }
             this.bg1.addChild(tempSpr);
            if (data && data.turnOut == 1 && tempSpr) //翻转放上面
            {
                let tempSpr2 = new Sprite();
               tempSpr2.graphics.drawTexture(tempSpr.texture, 0, 0, tempSpr.width, tempSpr.height);
                // tempSpr2.texture = tempSpr.texture;
                // tempSpr2.graphics.drawRect(0,0,100,500,"#ff00ff");
                //tempSpr2.scaleY = -1;
                tempSpr2.y = 100;

                // tempSpr2.scaleY = -1;
                // tempSpr2.y = maxY + GameManage.TopHeight;
                // this.bg1.addChild(tempSpr2);

                this.bg1.addChild(tempSpr2);
            }

        }
已邀请:

cuixueying

赞同来自:

不支持克隆一个sprite对象,建议你将该sprite类封装成一个单独的基类吧,然后通过new的方式创建!

要回复问题请先

商务合作
商务合作