Starling TouchEvent on Sprite

浪尽此生 提交于 2019-12-11 14:24:05

问题


I have some images/sprites/buttons (i tried them all :)) scrolling/moving on the stage. The user has to tap them to remove them.

The problem is that the touchevent does not match the position of the image. The faster the touchable sprites move, the further the distance between the touch and the actual image. i.e.:

a image is moving across the screen with 20px/frame: Touching the image triggers nothing, touching 20 before it triggers a touch on the image.

when image is not moving, this doesn't happen. It seems that the image is already moved internally, but not yet drawn to the screen, but thats just a wild guess. The example below uses a button, but the same goes for an image. I"ll provide a short example of the code, but i guess its pretty straightforward what i'm trying to do.

private var _image:Button;
protected function init():void {
    //create pickup image
    _image  = new Button(assets.getTexture("button"));
    _image.scaleWhenDown    = 1;
    _image.addEventListener(Event.TRIGGERED, onClick_image);
    addChild(_image);

    //listen to touch event (not used, but example for touch on image instead of button
    //touchable = true;
    //addEventListener(TouchEvent.TOUCH, onTouch_image);
}

private function onEnter_frame(e:Event):void {
    _image.x -= 20;
}

来源:https://stackoverflow.com/questions/16857841/starling-touchevent-on-sprite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!