在画布上绘制两个相同图像的问题
我在这里遇到一个问题,当我有 2 个痣时,它会崩溃,但如果只有一个,它就不会崩溃。
private int randX(){
int x = (int) Math.round((Math.random()*CollierSurface.getWidth()));
if (x<CollierSurface.getWidth()) randX();
return x;
}
private int randY(){
int y = (int) Math.round((Math.random()*CollierSurface.getHeight()));
if (y<CollierSurface.getWidth()) randY();
return y;
}
private void DrawMoles() {
if (!_canDraw) return;
try {
CollierCanvas = CollierHolder.lockCanvas();
Drawable background = getResources().getDrawable(R.drawable.collierabove);
background.setBounds(0, 0, CollierSurface.getWidth(), CollierSurface.getHeight());
background.draw(CollierCanvas);
newMole(randX(), randY(), mole1);
newMole(randX(), randY(), mole2);
} catch (SurfaceHolder.BadSurfaceTypeException e) {
} finally {
if (CollierCanvas != null){
CollierHolder.unlockCanvasAndPost(CollierCanvas);
}
}
}
private void newMole(int x, int y, Drawable mole){
mole = getResources().getDrawable(R.drawable.mole);
mole.mutate().setBounds((int)x-(mole.getIntrinsicWidth()),
(int)y-(mole.getIntrinsicHeight()),
(int)x+(mole.getIntrinsicWidth()),
(int)y+(mole.getIntrinsicHeight()));
mole.draw(CollierCanvas);
}
崩溃日志猫
03-19 17:48:14.342: ERROR/Setting(1969): USB debugging enabled
03-19 17:48:18.462: WARN/PowerManagerService(1928): Timer 0x3->0x3|0x1
03-19 17:48:18.777: ERROR/AndroidRuntime(10073): ERROR: thread attach failed
03-19 17:48:19.802: ERROR/AndroidRuntime(10081): ERROR: thread attach failed
03-19 17:48:19.927: WARN/Resources(1928): Converting to boolean: TypedValue{t=0x3/d=0xc4e "res/anim/accelerate_decelerate_interpolator.xml" a=2 r=0x10a0004}
03-19 17:48:19.947: WARN/Resources(1928): Converting to boolean: TypedValue{t=0x3/d=0xc4e "res/anim/accelerate_decelerate_interpolator.xml" a=2 r=0x10a0004}
03-19 17:48:19.962: WARN/ActivityThread(10088): Application com.collierhs.game is waiting for the debugger on port 8100...
03-19 17:48:22.647: ERROR/gralloc(1928): [unregister] handle 0x454ea0 still locked (state=40000001)
03-19 17:48:24.237: WARN/dalvikvm(10094): No implementation found for native Lcom/carrieriq/iqagent/client/NativeClient;.clientInit (Ljava/lang/Object;)I
03-19 17:48:39.750: WARN/ActivityManager(1928): Launch timeout has expired, giving up wake lock! 03-19 17:48:39.922: WARN/ActivityManager(1928): Activity idle timeout for HistoryRecord{4597c840 com.collierhs.game/.whack}
I am having a problem here it crashes when I have 2 moles, but if there is just one it doesnt crash.
private int randX(){
int x = (int) Math.round((Math.random()*CollierSurface.getWidth()));
if (x<CollierSurface.getWidth()) randX();
return x;
}
private int randY(){
int y = (int) Math.round((Math.random()*CollierSurface.getHeight()));
if (y<CollierSurface.getWidth()) randY();
return y;
}
private void DrawMoles() {
if (!_canDraw) return;
try {
CollierCanvas = CollierHolder.lockCanvas();
Drawable background = getResources().getDrawable(R.drawable.collierabove);
background.setBounds(0, 0, CollierSurface.getWidth(), CollierSurface.getHeight());
background.draw(CollierCanvas);
newMole(randX(), randY(), mole1);
newMole(randX(), randY(), mole2);
} catch (SurfaceHolder.BadSurfaceTypeException e) {
} finally {
if (CollierCanvas != null){
CollierHolder.unlockCanvasAndPost(CollierCanvas);
}
}
}
private void newMole(int x, int y, Drawable mole){
mole = getResources().getDrawable(R.drawable.mole);
mole.mutate().setBounds((int)x-(mole.getIntrinsicWidth()),
(int)y-(mole.getIntrinsicHeight()),
(int)x+(mole.getIntrinsicWidth()),
(int)y+(mole.getIntrinsicHeight()));
mole.draw(CollierCanvas);
}
Log cat of crash
03-19 17:48:14.342: ERROR/Setting(1969): USB debugging enabled
03-19 17:48:18.462: WARN/PowerManagerService(1928): Timer 0x3->0x3|0x1
03-19 17:48:18.777: ERROR/AndroidRuntime(10073): ERROR: thread attach failed
03-19 17:48:19.802: ERROR/AndroidRuntime(10081): ERROR: thread attach failed
03-19 17:48:19.927: WARN/Resources(1928): Converting to boolean: TypedValue{t=0x3/d=0xc4e "res/anim/accelerate_decelerate_interpolator.xml" a=2 r=0x10a0004}
03-19 17:48:19.947: WARN/Resources(1928): Converting to boolean: TypedValue{t=0x3/d=0xc4e "res/anim/accelerate_decelerate_interpolator.xml" a=2 r=0x10a0004}
03-19 17:48:19.962: WARN/ActivityThread(10088): Application com.collierhs.game is waiting for the debugger on port 8100...
03-19 17:48:22.647: ERROR/gralloc(1928): [unregister] handle 0x454ea0 still locked (state=40000001)
03-19 17:48:24.237: WARN/dalvikvm(10094): No implementation found for native Lcom/carrieriq/iqagent/client/NativeClient;.clientInit (Ljava/lang/Object;)I
03-19 17:48:39.750: WARN/ActivityManager(1928): Launch timeout has expired, giving up wake lock! 03-19 17:48:39.922: WARN/ActivityManager(1928): Activity idle timeout for HistoryRecord{4597c840 com.collierhs.game/.whack}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是随机的 x 和 y 花费太长时间来制作
我现在要使用它
It's the random x and y is taking too long to make
I'm gonna use this now