简体   繁体   English

java 2d游戏中的碰撞检测

[英]Collision detection in java 2d game

I'm trying to detect in memory, when user invade mouse on some object, like tree.我试图在内存中检测,当用户在某个对象(如树)上侵入鼠标时。 But checking each pixel is too low, and another problem is that my tree.png have size 64x64, but real tree is smaller, and i was trying to get array of pixels, who's real image.但是检查每个像素太低,另一个问题是我的 tree.png 大小为 64x64,但真正的树更小,我试图获取像素数组,谁是真实图像。 My game is in isometric projection.我的游戏是等距投影。 And is there any good way, to detect when user invade mouse on object?有什么好方法可以检测用户何时在对象上侵入鼠标?

You can assign each object a coordinate.您可以为每个对象分配一个坐标。 Then you calculate the distance between mouse and object.然后计算鼠标和对象之间的距离。 If the distance is less than the mouse radius, then the objects overlap or touch.如果距离小于鼠标半径,则对象重叠或接触。

Second possibility: You assign each object a bounding box (rectangle around center of object).第二种可能性:您为每个对象分配一个边界框(围绕对象中心的矩形)。 Then you check wheter the rectangles intersect.然后检查矩形是否相交。 (see Rectangle2D ) (见Rectangle2D

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

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