0

我很难使用带有羽毛 ui 的 Starling 来工作。

这是我的代码:

function begin(){



        var quadx = squareSize/4 + squareSize/8;
        var quady = 20;
        var quadcounter = 0;

        for(var f=0;f<totalsquares;f++){    



        var sprite:Sprite = new Sprite();




    var quad:Quad = new Quad(squareSize, squareSize);
    sprite.name = "" + f;
    spriteunder.name = "" + f * 1000;
    quad.setVertexColor(0, 0x3683ed);
    quad.setVertexColor(1, 0x3683ed);
    quad.setVertexColor(2, 0x3683ed);
    quad.setVertexColor(3, 0x3683ed);


    sprite.x=quadx;
    sprite.y = quady;


    var lv3 = new TextField(squareSize, squareSize, f,"Corpid", 14,0xf1f1f1);


    sprite.touchable = true;
    quad.touchable = true;

    lv3.touchable = false;
        sprite.addChild(quad);
    sprite.addChild(lv3);   



    addChild(sprite);


    sprite.addEventListener(TouchEvent.TOUCH, touchHandler); 




    quadx = quadx + squareSize + 1;

    quadcounter++;


if(quadcounter == boardWidth){

    quadx =  squareSize/4 + squareSize/8;
    quady = quady + squareSize + 1;
    quadcounter = 0;
}

}



}


function touchHandler(e : TouchEvent) : void 
  {
   var touch:Touch = e.getTouch(stage);
   var position:Point = touch.getLocation(stage);
   var target:Quad = e.target as Quad;

   if(touch.phase == TouchPhase.MOVED ){
    target.x = position.x - target.width/2;
    target.y = position.y - target.height/2;
    }
  }

问题是,每当我运行它时,它都会被拖来拖去,而不是父精灵。

为了让它正确拖动,我做了什么改变。

4

1 回答 1

0

也许你必须从

var touch:Touch = event.getTouch(this, TouchPhase.BEGAN);
if (touch)
{
    //get and lock your target, maybe a trace of your actual target, just to be sure!
}

然后在 MOVED 阶段,实际拖动它。

于 2013-11-07T23:19:44.427 回答