【发布时间】:2017-02-13 00:17:05
【问题描述】:
在游戏开发方面,我几乎是一个初学者,尤其是使用 Libgdx,到目前为止,我做到了,所以我可以加载任何 .tmx 地图或保存它,我可能会尝试看看如何在程序上生成地形可以工作,但是现在当我删除一个块(该块由 TiledMapTile 和 box2d 主体组成)时,我遇到了这个奇怪的错误,我正在删除它,删除后我正在创建一个更小的实体,它也将是一个主体,代表我刚刚删除的块,作为播放器的放置,这是我单击一个块时遇到的错误,它只发生在第一个块被删除后,所以,一个块被删除并且一个创建了一个小实体,但如果我再次尝试这样做,游戏就会中断并出现:
Java 运行时环境检测到致命错误:
PC=0x00007ffb8ecd9f58, pid=6580, tid=0x0000000000002474 处的异常_访问权限 (0xc0000005)
JRE 版本:Java(TM) SE 运行时环境 (8.0_121-b13) (build 1.8.0_121-b13) Java VM:Java HotSpot(TM) 64 位服务器 VM(25.121-b13 混合模式 windows-amd64 压缩 oops) 有问题的框架: C [ntdll.dll+0x39f58]
无法写入核心转储。默认情况下,在 Windows 的客户端版本上不启用小型转储
包含更多信息的错误报告文件保存为: C:\Libgdx Projects Fedora\WINDOWS\Generator Test\core\assets\hs_err_pid6580.log
如果您想提交错误报告,请访问: http://bugreport.java.com/bugreport/crash.jsp 崩溃发生在 Java 虚拟机之外的本地代码中。 请参阅有问题的框架以了解报告错误的位置。
[报错时发生错误,id 0xc0000005]
这是错误日志:
这是我删除块的地方:
public void destroyTerrain( ArrayList<Block> terrain, ArrayList<BlockDrop> blockDropsList ) {
int x = Gdx.input.getX() / 32;
int y = ( Gdx.graphics.getHeight() - Gdx.input.getY() ) / 32;
Iterator<Block> iterator = terrain.iterator();
while ( iterator.hasNext() ) {
Block block = iterator.next();
if ( x == ( int ) block.getBody().getPosition().x && y == ( int ) block.getBody().getPosition().y ) {
PolygonShape shape = ( PolygonShape ) block.getBody().getFixtureList().get( 0 ).getShape();
world.destroyBody( block.getBody() );
iterator.remove();
TiledMapTileLayer.Cell cell = ( ( TiledMapTileLayer ) map.getLayers().get( 0 ) ).getCell( x, y );
Texture tex = cell.getTile().getTextureRegion().getTexture();
// this is where the error is happening, when I'm creating a second blockDrop
BlockDrop blockDrop = new BlockDrop( screen, x, y, shape.getRadius() * 16, shape.getRadius() * 16 );
blockDrop.setTexture( tex );
blockDropsList.add( blockDrop );
cell.setTile( null );
}
}
}
这是 BlockDrop 类:
public class BlockDrop extends Entity {
public BlockDrop( PlayGame screen, int x, int y, float width, float height ) {
super( screen );
posX = x;
posY = y;
type = BodyDef.BodyType.DynamicBody;
density = 0.2f;
friction = 0.4f;
shape = new PolygonShape();
( ( PolygonShape ) shape ).setAsBox( width, height, new Vector2( ( x / 32 ) + width * 2, ( y / 32 ) + height * 2 ), 0 );
createBody();
}
}
这就是实体:
abstract public class Entity {
private PlayGame screen;
float posX, posY;
private Body body;
Shape shape;
BodyDef.BodyType type;
float density;
float friction;
SpriteBatch batch;
Sprite sprite;
Entity( PlayGame screen ) {
this.screen = screen;
batch = new SpriteBatch();
sprite = new Sprite();
}
void createBody( ) {
BodyDef bodyDef = new BodyDef();
bodyDef.type = type;
bodyDef.position.set( posX, posY );
body = screen.getWorld().createBody( bodyDef );
body.setUserData( this );
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = shape;
fixtureDef.density = density;
fixtureDef.friction = friction;
body.createFixture( fixtureDef );
dispose();
}
public void setTexture(Texture tex){
sprite.setTexture( tex );
}
public void render( ) {
sprite.setBounds( posX, posY, shape.getRadius(), shape.getRadius() );
batch.begin();
sprite.draw( batch );
batch.end();
}
public String toString( ) {
return getClass().getSimpleName();
}
public Body getBody( ) {
return body;
}
public void dispose( ) {
shape.dispose();
batch.dispose();
}
}
任何帮助将不胜感激,这可能只是一个简单的愚蠢的事情,代码现在可能一团糟,但我似乎无法解决这个问题
【问题讨论】:
标签: java arraylist libgdx textures