AS3 / AIR移动点击和/或移动的物体touchevents物体、AIR、touchevents

2023-09-08 14:15:51 作者:丈母娘,你能不能快点发货

几个星期前,我问一个关于similair问题的问题,但德裕框架(在椋鸟的TouchEvent上雪碧)

few weeks ago i asked a question about a similair issue, but within the Starling Framework (Starling TouchEvent on Sprite)

现在,我工作的另一个移动应用/游戏Away3D中。我似乎有同样的问题触摸/轻敲移动球或框。当球体不动,我可以直接点击它正是在它的位置,但是当它旋转时,点击事件犯规火非常准确。 这只是发生在手机上(Android上4.2.2测试:Nexus7 / GALAXY S2和iOS:iPad2的/ iPad的视网膜)

Now, i am working on another mobile app/game with Away3d. I seem to have the same problem touching/tapping a moving sphere or box. When the sphere is not moving, i can just tap it exactly at its position, but when it rotates, the click-event doesnt fire very accurate. this only happens on Mobile (tested on Android 4.2.2: Nexus7/Galaxy S2 and iOS: iPad2/iPad Retina)

package {
import away3d.containers.ObjectContainer3D;
import away3d.containers.View3D;
import away3d.core.pick.PickingColliderType;
import away3d.core.pick.PickingType;
import away3d.debug.AwayStats;
import away3d.entities.Mesh;
import away3d.events.MouseEvent3D;
import away3d.primitives.SphereGeometry;

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Vector3D;

[SWF(frameRate="60")]
public class Main extends Sprite {
    private var _container:ObjectContainer3D;
    private var _view:View3D;
    private var _sphere:Mesh;
    public function Main()
    {
        super();

        addEventListener(Event.ADDED_TO_STAGE, onAdded_toStage);
    }

    private function onAdded_toStage(e:Event):void {
        removeEventListener(Event.ADDED_TO_STAGE, onAdded_toStage);

        stage.align         = StageAlign.TOP_LEFT;
        stage.scaleMode     = StageScaleMode.NO_SCALE;

        stage.addEventListener(Event.RESIZE, onResize_stage);

        init3d();
    }

    private function onResize_stage(e:Event):void {
        _view.width     = stage.stageWidth;
        _view.height    = stage.stageHeight;
    }

    private function onEnter_frame(e:Event):void {
        _container.rotationY += 1;
        _view.render();
    }

    private function onClick_sphere(e:MouseEvent3D):void {
        //reposition the sphere
        var deg:Number          = Math.random() * 360;
        _sphere.x               = 250 * Math.cos(deg);
        _sphere.z               = 250 * Math.sin(deg);
        _sphere.y               = 80 + (Math.random() * 40);
    }

    private function init3d():void {
        //create the 3d-view
        _view               = new View3D();
        _view.width         = stage.stageWidth;
        _view.height        = stage.stageWidth;
        addChild(_view);

        //create a cub
        _view.camera.z = -400;
        _view.camera.y = 75;
        _view.camera.lookAt(new Vector3D(0, 125, 0));

        //create container
        _container = new ObjectContainer3D();
        _view.scene.addChild(_container);

        //create sphere to tap
        _sphere                 = new Mesh(new SphereGeometry(10));
        _sphere.pickingCollider = PickingColliderType.AS3_FIRST_ENCOUNTERED;
        _sphere.y               = 100;
        _sphere.z               = -250;
        _sphere.mouseEnabled = true;
        _sphere.addEventListener(MouseEvent3D.CLICK     , onClick_sphere);
        _container.addChild(_sphere);

        var stats:AwayStats = new AwayStats(_view);
        addChild(stats);

        addEventListener(Event.ENTER_FRAME, onEnter_frame);
    }
}

注:我也尝试过不同的帧速率,更多的事件(MOUSE_UP,下降等),不同采摘

NOTE: i also tried different framerates, more events(Mouse_up, down etc), different pickers.

由于这个问题也发生在2D转换精灵(在八哥)我的猜测是可能的Stage3D或AIR相关的,而不是八哥/ Away3D中。

As this problem also happens with 2d moving sprites (in starling) my guess is that is might be Stage3D or AIR related, instead of starling/away3d.

任何人有一些建议?也许我忘了设定的东西在app.xml中?

Anyone has some suggestions? Maybe i'm forgetting to set something in the app.xml?

推荐答案

这两个框架必须处理的事件较少的系统(Stage3D的)。 Stage3D的不捕获或接收任何事件和certianly不要触摸或鼠标事件。因此,这两个框架模拟与内部系统,捕获事件在舞台上的这些事件,并尝试重现一个准确的估计。我个人认为这些系统过于昂贵的CPU和不够准确,所以我的建议是不喜欢我,创建你自己的系统。简单地赶上活动的舞台上,并决定其显示的对象(使用Stage3D的自己的位置)被触摸。我个人得到的性能提升了它(尤其是八哥)和更准确。

Both framework have to deal with an event less system (Stage3D). Stage3D doesn't catch or receive any events and certianly not touch or mouse event. So both frameworks simulate those events with an internal system that catches events on the stage and try to reproduce an accurate estimation. I personally find those systems too CPU expensive and not accurate enough so my advice is to do like me, create your own system. Simply catch event on the stage and decide which of displayed objects (on Stage3D using their position) has been touched. I personally get a performance boost out of it (especially with starling) and much more accuracy.