gpt4 book ai didi

java - 当屏幕太大时出现错误

转载 作者:行者123 更新时间:2023-11-30 00:38:45 25 4
gpt4 key购买 nike

我最近上传了一个 app到谷歌游戏商店。它适用于某些设备,但不适用于像 nexus 7 这样的大型设备。我得到以下堆栈跟踪:

java.lang.IllegalArgumentException: x + width must be <= bitmap.width()
at android.graphics.Bitmap.createBitmap(Bitmap.java:667)
at android.graphics.Bitmap.createBitmap(Bitmap.java:634)
at de.krissini.server.Player.<init>(Player.java:26)
at de.krissini.server.GamePanel.surfaceCreated(GamePanel.java:64)

这里是引用代码。游戏面板:

@Override
public void surfaceCreated(SurfaceHolder holder) {
setWillNotDraw(false);
score = 0;
fuel = 50;
bg = new Background(BitmapFactory.decodeResource(getResources(), R.raw.grassbg1), 1000);
player = new Player(BitmapFactory.decodeResource(getResources(), R.raw.helicopter), 132, 47, 3); // line 64
scoreStartTime = System.nanoTime();
smoke = new ArrayList<Smokepuff>();
smokestartTime = System.nanoTime();
missles = new ArrayList<Missle>();
missleStartTime = System.nanoTime();
thread = new MainThread(getHolder(), this);

// start game loop
thread.setRunning(true);
thread.start();
}

玩家:

public Player(Bitmap res, int w, int h, int numFrames) {
x = 100;
y = GamePanel.HEIGHT / 2;
dy = 0;
score = 0;
height = h;
width = w;
spritesheet = res;
Bitmap[] image = new Bitmap[numFrames];
for(int i = 0; i<image.length; i++){
image[i] = Bitmap.createBitmap(spritesheet, i*width, 0, width, height); // line 62
}

animation.setFrames(image);
animation.setDelay(10);
startTime = System.nanoTime();
}

我该怎么做才能摆脱这个错误?我感谢每一个答案!

最佳答案

Bitmap.createBitmap(spritesheet, i*width, 0, width, height);

对于这个魔数(Magic Number) 132, 47 无效

x + width must be <= bitmap.width()

关于java - 当屏幕太大时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42921898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com