八哥的TouchEvent对雪碧 [英] Starling TouchEvent on Sprite

查看:150
本文介绍了八哥的TouchEvent对雪碧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些图像/精灵/按钮(我想他们都:))滚动/移动在舞台上。用户必须挖掘他们删除它们。

的问题是,使用TouchEvent不匹配的图像的位置。 越快触摸精灵移动,触摸和实际图像之间的进一步的距离。即:

一个图像移过与20像素/帧的画面: 触摸图像触发什么,触及20它触发图像上的触摸之前。

当图像不移动,这不会发生。它似乎像已在内部移动,但尚未绘制到屏幕上,但是那只是胡乱猜测。下面的例子使用一个按钮,但同样也适用于一个图像。我会提供的code一个简单的例子,但我想它的pretty的直白我想要做的。

 私人变种_image:按钮;
保护功能的init():无效{
    //创建一个拍摄图像
    _image =新按钮(assets.getTexture(按钮));
    _image.scaleWhenDown = 1;
    _image.addEventListener(Event.TRIGGERED,onClick_image);
    的addChild(_image);

    //监听触摸事件(不使用,但例如触摸图像代替按钮
    //触摸= TRUE;
    //addEventListener(TouchEvent.TOUCH,onTouch_image);
}

私有函数onEnter_frame(五:事件):无效{
    _image.x  -  = 20;
}
 

解决方案

可能是你应该尽量听点击赛事的舞台上,而不是图像(你知道它能够更好地把事件侦听器,以舞台上,然后看了他的 currentTarget当前属性来获取,实际上是pressed特定对象)。这是一件好事来表现,所以可能是它可以解决你的问题了。

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;
}

解决方案

May be you should try listening to click event on the stage and not on the image (you know its better to attach event listener to stage and then read his currentTarget property to get specific object that is actually pressed). It is always good to performance ,so may be it can fix your issue too.

这篇关于八哥的TouchEvent对雪碧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆