我正在制作一个旧的超级马里奥的克隆,当我的小马里奥从下面击中它时,我正在试图摇动砖瓦。这个概念取自Brent Aureli的一篇很棒的libgdx教程以及他编写/展示的所有内容,但是当我做这个(看似很小的)修改时,修改本身就很奇怪。
即,当小马里奥击中瓷砖(任何砖瓦)时,所有这种瓷砖都会得到这种偏移。根据我的理解,访问权限为getCell().getTile().setOffsetY(value)
,这应该是
获得单个细胞 - >在该单元格中获取平铺 - >将offset设置为给定单元格中的这个tile。 文档还建议它应该这样工作:
https://libgdx.badlogicgames.com/nightlies/docs/api/
当大马里奥击中平铺按预期工作时,将tile替换为null,因此我不明白为什么getCell.getTile的方法没有。
最后,我意识到细胞是不动的,我想要的只是实际纹理的纯粹化妆品移动半秒左右 - 这是可能的,但在当前状态下它会抵消所有类似的瓷砖
为了它的乐趣我
public class Brick extends InteractiveTile {
private static TiledMapTileSet tileSet;
public Brick(PlayScreen screen, MapObject object) {
super(screen, object);
tileSet = screen.getMap().getTileSets().getTileSet("tileset_gutter");
fixture.setUserData(this);
setCategoryFilter(SuperMario.BRICK_BIT);
}
@Override
public void onHeadHit(Mario mario) {
if(mario.isBig()){
SuperMario.manager.get("audio/breakblock.wav", Sound.class).play();
setCategoryFilter(SuperMario.DESTROYED_BIT);
getCell().setTile(null);
}
else {
SuperMario.manager.get("audio/bump.wav", Sound.class).play();
// DOES THE EXACT SAME AS LATER 3 LINES
// getCell().getTile().setOffsetY(2);
getCell().setTile(tileSet.getTile(28)); //this can change texture of individual tile.
TiledMapTile tile = getCell().getTile();
tile.setOffsetY(2);
getCell().setTile(tile);
}
}
}
InteractiveTile:
public abstract class InteractiveTile {
private World world;
private TiledMap map;
private TiledMapTile tile;
private Rectangle bounds;
protected Body body;
protected final Fixture fixture;
protected PlayScreen screen;
protected MapObject object;
public InteractiveTile(PlayScreen screen, MapObject object){
this.screen = screen;
this.world = screen.getWorld();
this.map = screen.getMap();
this.object = object;
this.bounds = ((RectangleMapObject)object).getRectangle();
BodyDef bdef = new BodyDef();
FixtureDef fdef = new FixtureDef();
PolygonShape shape = new PolygonShape();
bdef.type = BodyDef.BodyType.StaticBody;
bdef.position.set(
(bounds.getX()+ bounds.getWidth()/2)/ SuperMario.PPM,
(bounds.getY() + bounds.getHeight()/2)/SuperMario.PPM);
body = world.createBody(bdef);
shape.setAsBox(
(bounds.getWidth()/2)/SuperMario.PPM,
(bounds.getHeight()/2)/SuperMario.PPM); fdef.shape = shape;
fixture = body.createFixture(fdef);
}
public abstract void onHeadHit(Mario mario);
public TiledMapTileLayer.Cell getCell(){
TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(1);
return layer.getCell(
//REVERT SCALING (PPM) AND by tile size
(int)(body.getPosition().x * SuperMario.PPM / 16),
(int)(body.getPosition().y * SuperMario.PPM / 16));
}
public void setCategoryFilter(short filterBit){
Filter filter = new Filter();
filter.categoryBits = filterBit;
fixture.setFilterData(filter);
}
}
此代码中是否有错误,或者它是引擎的限制?
PS - 原始(未修改)文件可以在Brent Aurelis github网站上找到: