java polygon 用法_java – LibGDX – 正确使用Polygon类

我已经创建了Polygon对象来包裹我的飞机(飞机的TextureRegion的大小是256×74,但是这个游戏的大小是70×20).所以:

TextureRegion[] texRegsAirplane = TextureRegion.split(textureAirplane, 256, 74);

Rectangle bounds = new Rectangle(0, 0, 70, 20);

Polygon polygon = new Polygon(new float[]{0,0,bounds.width,0,bounds.width,bounds.height,0,bounds.height,0,0});

在我的更新功能之后,我更新它的位置:

public void update(float delta){

Vector2 v = getPosition();

v.add(velocity);

polygon.setPosition(v.x, v.y);

}

然后我渲染多边形以了解它的位置:

public void render(SpriteBatch spriteBatch, float pixelPerUnitX, float pixelPerUnitY){

spriteBatch.draw(testTexture,polygon.getX()*pixelPerUnitX, polygon.getY()*pixelPerUnitY,

polygon.getBoundingRectangle().width*pixelPerUnitX,polygon.getBoundingRectangle().height*pixelPerUnitY);

}

最后,我创建了2架飞机,让它们相互飞行,每次迭代我都会尝试检测碰撞,如下所示:

public void detectCollision(){

for(Airplane airplane1 : Airplanes){

for(Airplane airplane2 : Airplanes){

if(Intersector.overlapConvexPolygons(airplane1.getPolygon(), airplane2.getPolygon())){

//COLLISION DON'T HAPPEN!!!

}

}

}

我看到2个矩形相互移动并相交,但overlapConvexPolygons函数不起作用!为什么?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值