当两个ImageView相互交叉时,我正试图让事情发生.这是我使用的代码:
Rect rect1 = new Rect();
imageView.getHitRect(rect1);
Rect rect4 = new Rect();
imageView2.getHitRect(rect4);
boolean collision = false;
collision = rect1.intersect(rect4);
if(collision = true){
button.setText("collided");
}else
button.setText("not collided");
Run Code Online (Sandbox Code Playgroud)
但是,当应用程序启动时,布尔值才会更改为true.第一个ImageView保持静止,而另一个移动到第一个(它不是精灵,但是它朝着第一个ImageView的方向移动并移过它).我希望布尔值在两个ImageView相交时改变.有什么我想念的吗?
我想在Android代码中设置一个数字平方(例如,x ^ 2),但是我收到此错误:
对于参数类型int,boolean,运算符^未定义
是否有一种不同的方式来对Android中的数字/变量进行平方?
我试图让我的Android应用程序在尝试执行if语句之前等待几秒钟.我听说有些人说不使用thread.sleep()方法,那么还有更好的方法吗?这是我试图做的,这是行不通的
try {
Thread.sleep( 1500 );
}
catch( InterruptedException e ) {
e.printStackTrace();
}
if( playerimage.getVisibility() == View.VISIBLE ) {
currentscore.setText( "Game over" );
}
Run Code Online (Sandbox Code Playgroud)