简体   繁体   English

我需要某种用于Android的刚体碰撞检测引擎

[英]I need some sort of rigid body collision detection engine for Android

I have tried to make my own to work on Android, but I have failed. 我试图使自己的作品在Android上运行,但失败了。 What I mean with rigid body collision detection is that basically there is a wall and as soon as the player touches the wall, it cannot go through. 我指的是刚体碰撞检测,基本上就是有一堵墙,玩家一碰到墙,它就无法通过。 I have tried to use Box2D, Emini Engine, PPhys2D, Phys2D, and either they dont have enough tutorials or they are really complicated. 我尝试使用Box2D,Emini Engine,PPhys2D,Phys2D,或者它们没有足够的教程,或者它们确实很复杂。 I wrote this to use with my normal Java games: 我将其编写为用于普通Java游戏:

//package
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DCDE {
int plx, ply, obx, oby, obw, obh, plw, plh;
Rectangle north;
Rectangle east;
Rectangle south;
Rectangle west;
boolean debug=true;
public void debug(Graphics g)
{
    Graphics2D g2 = (Graphics2D)g;
    if(debug)
    {
        if(!(north==null)&&!(east==null)&&!(south==null)&&!(west==null)){
            g2.setColor(Color.YELLOW);
            g2.draw(north);
            g2.draw(east);
            g2.draw(south);
            g2.draw(west);
            g2.fill(north);
            g2.fill(east);
            g2.fill(south);
            g2.fill(west);
        }
    }
}
public void detect(int plxj, int plyj, int obxj, int obyj, int obwj, int obhj, int plwj, int plhj)
{
    plx=plxj;
    ply=plyj;
    obx=obxj;
    oby=obyj;
    obw=obwj;
    obh=obhj;
    plw=plwj;
    plh=plhj;
    Rectangle playr = new Rectangle(plx, ply, plw, plh);
    Rectangle objr = new Rectangle(obx, oby, obw, obh);
    north = new Rectangle((obx), (oby-1), obw, 1);
    east = new Rectangle((obx+obw), (oby), 1, obh);
    south = new Rectangle((obx), (oby+obh)+1, obw, 1);
    west = new Rectangle((obx-1), oby, 1, obh);
    if(playr.intersects(north)){
        ply=(oby-plh-1);
        if(debug)System.out.println("NORTH");
    }
    if(playr.intersects(east)){
        plx=(obx+obw+1);
        if(debug)System.out.println("EAST");
    }
    if(playr.intersects(south)){
        ply=(oby+obh+1);
        if(debug)System.out.println("SOUTH");
    }
    if(playr.intersects(west)){
        plx=(obx-plw-1);
        if(debug)System.out.println("WEST");
    }
}
}

This worked fine on the computer-java games i had made, but now I need something like the above but for android. 在我制作的计算机Java游戏上,此方法效果很好,但现在我需要类似上面的内容,但适用于android。 So is there some sort of engine JUST made for collision detection and not the whole gravity stuff, or is there some easy maths way I could use? 那么,有没有只是为了碰撞检测而制造的某种引擎,而不是整个重力的东西,还是有一些我可以使用的简单数学方法?

Thanks in advance. 提前致谢。

Why not just use a graphics engine that already works on android, like Unity or AndEngine . 为什么不只使用已经可以在android上运行的图形引擎,例如UnityAndEngine I'm they've already have thing kind of stuff built in along with a bunch of other nice things. 我是他们已经内置了一些东西以及许多其他好东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM