我试图让自己在Android上工作,但我失败了。刚性身体碰撞检测的意思是,基本上有一堵墙,一旦玩家接触到墙壁,它就无法通过。我曾尝试使用Box2D,Emini Engine,PPhys2D,Phys2D,要么他们没有足够的教程,要么他们真的很复杂。我写这个用于我的普通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");
}
}
}
这在我制作的计算机java游戏上运行良好,但现在我需要类似上面的内容但是对于android。那么是否有某种引擎只能用于碰撞检测,而不是整个重力的东西,还是有一些简单的数学方法我可以使用?
提前致谢。