java - PlayN 用触摸板 throw 物体

标签 java gwt playn 2d-games

我正在使用 PlayN 构建一个涉及石头的游戏,用户必须在物理世界中移动(通过重力等)。我希望用户能够使用触摸板直接操纵石头,并通过以下方式给它们一个速度拖拽并扔掷它们。

现在我有一个实现,其中每个石头都在自己的层上,并且我在石头层上有一个监听器,该监听器将停用该石体的物理功能(当用户捕获它时)并在拖动完成后重新激活。

问题是监听器回调的执行似乎有延迟,这意味着在考虑重新激活物理引擎之前会显示许多帧,导致用户停止抓取后石头落下的延迟。

针对此类行为还有其他方法吗?我错过了什么吗?

谢谢!

  layer.addListener(new Pointer.Adapter() {

        @Override
        public void onPointerStart(Event event) {
            suspendPhysik = true;
            getBody().setActive(!suspendPhysik);

        }

        @Override
        public void onPointerEnd(Event event) {
            suspendPhysik = false;
            getBody().setActive(!suspendPhysik);
            long deltatime = System.currentTimeMillis() - prevTimestamp;
            Vec2 velocity = new Vec2((event.x()
                    * NewGame.physUnitPerScreenUnit - prevX)
                    / deltatime,
                    (event.y() * NewGame.physUnitPerScreenUnit - prevX)
                            * NewGame.physUnitPerScreenUnit / deltatime);
            getBody().setLinearVelocity(velocity);
        }

        @Override
        public void onPointerDrag(Event event) {
            x = event.x() * NewGame.physUnitPerScreenUnit;
            y = event.y() * NewGame.physUnitPerScreenUnit;
            setPos(event.x() * NewGame.physUnitPerScreenUnit, event.y()
                    * NewGame.physUnitPerScreenUnit);
        }

    });`

最佳答案

发现一个关于 playN 的有趣演示。

http://playn-2011.appspot.com/slides/index.html#34

在示例中作者使用以下代码:

touch().setListener(new Touch.Adapter() {           
    @Override
    public void onTouchStart(Event[] touches) {
      // Process touch events into a zoom start position.
    }   
    @Override
    public void onTouchMove(Event[] touches) {
      // Update zoom based on touches.
    }              
});

此链接包含 Touch.Adapter 的文档 http://docs.playn.googlecode.com/git/javadoc/playn/core/Touch.Adapter.html#Touch.Adapter()

所以试试这个:

layer.addListener(new Touch.Adapter() {         
    @Override
    public void onTouchStart(Touch.Event[] touches) {
        suspendPhysik = true;
        getBody().setActive(!suspendPhysik);
    }   

    @Override
    public void onTouchMove(Touch.Event[] touches) {
        suspendPhysik = false;
        getBody().setActive(!suspendPhysik);
        long deltatime = System.currentTimeMillis() - prevTimestamp;
        Vec2 velocity = new Vec2((touches[0].x() * NewGame.physUnitPerScreenUnit - prevX) / deltatime, (event.y() * NewGame.physUnitPerScreenUnit - prevX) * NewGame.physUnitPerScreenUnit / deltatime);
        getBody().setLinearVelocity(velocity);
    }   

    @Override
public void onTouchMove(Touch.Event[] touches)  
    {
        x = touches[0].x() * NewGame.physUnitPerScreenUnit;
        y = touches[0].y() * NewGame.physUnitPerScreenUnit;
        setPos(x * NewGame.physUnitPerScreenUnit, y * NewGame.physUnitPerScreenUnit);
    }   
  });

关于java - PlayN 用触摸板 throw 物体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18308972/

相关文章:

GWT 历史记录删除项目

GWT 事件和地点 : Reusing modal dialogs?

java - Maven 和 gwt 项目

java - (JTDS) java.sql.SQLException : Error converting data type nvarchar to numeric

java - ksoap2 将 String[] 设置为 request.addProperty

java - 克洛贾尔/Java : Most effective method for minimizing bandwidth consumption when performing complex operations on a stream of Amazon S3 data

java - 如何检查 'only one jRadiobutton should be selected'的条件

maven安装失败

ios - 在 Xamarin 中加载 PlayN 声音 Assets

maven - 无法找到魔力 'generate-sources'