简体   繁体   中英

ArrayIndexOutOfBoundsException with sprite sheet

I keep getting this error with andengine when using a sprite sheet.

Can anyone explain what i means?

08-30 13:31:50.053: E/AndroidRuntime(9643): java.lang.ArrayIndexOutOfBoundsException: length=12; index=12

here is where the error is occuring at.

    pItem.setCurrentTileIndex(MathUtils.random(0, pItem.getTileCount()));

try: pItem.setCurrentTileIndex(MathUtils.random(0, pItem.getTileCount()-1));

getTileCount() likely returns the # of tiles, so indexes would be that minus 1.

我的猜测是MathUtils.random是包容性的,这意味着在你的例子中(大小为12的数组),它将生成一个从0到12的数字, 包括 12.尝试将代码更改为:

pItem.setCurrentTileIndex(MathUtils.random(0, pItem.getTileCount() - 1));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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