Android 将矩形附加到imageview,使其跟随无限动画循环
我似乎不知道如何移动我的矩形以及我正在制作动画以用作点击框的图像视图。我让它检测与相交的碰撞,但它只是停留在图像的起始位置 我破解它的第一个方法是使用Android 将矩形附加到imageview,使其跟随无限动画循环,android,Android,我似乎不知道如何移动我的矩形以及我正在制作动画以用作点击框的图像视图。我让它检测与相交的碰撞,但它只是停留在图像的起始位置 我破解它的第一个方法是使用getOnScreenLocation()并将其存储在一个变量中,以使用rect上的offsetTo()将其与图像一起移动,但这只会将hitbox移动到动画的末尾,就是这样。我有我的hitbox移动,并检查seprate线程内的冲突,频繁更新UI 因此,我的问题是,如何使rect点击框在屏幕上设置动画时保持与imageview的连接?任何和所有的建
getOnScreenLocation()
并将其存储在一个变量中,以使用rect上的offsetTo()
将其与图像一起移动,但这只会将hitbox移动到动画的末尾,就是这样。我有我的hitbox移动,并检查seprate线程内的冲突,频繁更新UI
因此,我的问题是,如何使rect点击框在屏幕上设置动画时保持与imageview的连接?任何和所有的建议都有帮助,即使这只是一种我应该研究的方法,谢谢
这是mymoveHitbox()
的最新版本,但仍无法正常运行
public void hitBox()
{
//declaration of rectangles around each image
getHits();
moveHitBox();
//see if rectangle around rocket intersects enemy ships rectangle
if (Rect.intersects(myViewRect, otherViewRect1)||Rect.intersects(myViewRect,
otherViewRect2) ||Rect.intersects(myViewRect, otherViewRect3)) {
check();
//immunity();
}
}
public void moveHitBox()
{
int YYY = (int)enemy_ship.getTranslationY();
int XXX = (int)enemy_ship.getTranslationX();
enemy_ship.setTranslationY(YYY);
enemy_ship.setTranslationX(XXX);
enemy_ship.getLocationOnScreen(thisLocation);
enemy_ship2.getLocationOnScreen(thisLocationA);
enemy_ship3.getLocationOnScreen(thisLocationB);
x.getLocationOnScreen(thisShipLocation);
otherViewRect1.union(thisLocation[0],thisLocation[1]);
otherViewRect2.union(thisLocationA[0], thisLocationA[1]);
otherViewRect3.union(thisLocationB[0],thisLocationB[1]);
}
// Separate thread that updates the ui thread
Runnable myRunnable = new Runnable() {
@Override
public void run() {
while (testByte == 0) {
try {
Thread.sleep(3); // Waits for 1 second (1000 milliseconds)
}catch(InterruptedException e)
{
finish();
}
enemy_ship.post(new Runnable() {
@Override
public void run() {
hitBox();
}
});
}
}
};
您可以删除这些评论,因为我已将它们添加到您的问题中。您可以删除这些评论,因为我已将它们添加到您的问题中。