【问题标题】:How can I know where the user touches?(AIR for android)我如何知道用户触摸的位置?(AIR for android)
【发布时间】:2012-03-07 08:56:19
【问题描述】:

我正在尝试在用户触摸时执行此操作(不是用鼠标单击程序在 android 上运行) 代码获取触摸 x 和 y 的(位置)(如 _xmouse,但它在 android 上不起作用) 我该怎么做? 谢谢!

【问题讨论】:

  • 就像 MouseEvent ,本地和舞台属性。

标签: android actionscript-3 flash air


【解决方案1】:

你必须为一个TouchEvent设置一个事件监听函数,如果你得到一个参数,你可以使用以下属性:

  • stageX:事件发生的水平坐标在全局舞台坐标中。

  • stageY:全局舞台坐标中事件发生的垂直坐标。

  • localX:事件发生时相对于包含精灵的水平坐标。

  • localY:事件发生时相对于包含精灵的垂直坐标。

例如:

mySprite.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);


function onTouchBegin(e:TouchEvent)
{
     trace("local coords (relatives to mySprite): " + e.localX+" "+e.localY);
     trace("global coords: " + e.stageX+" "+e.stageY);

}

欲了解更多信息,请查看Adobe reference for TouchEvent here

【讨论】:

    猜你喜欢
    • 2012-04-14
    • 2016-04-26
    • 1970-01-01
    • 2015-03-02
    • 1970-01-01
    • 1970-01-01
    • 2011-03-29
    • 1970-01-01
    • 2015-05-29
    相关资源
    最近更新 更多