所以我正在关注超级马里奥的Brent Aureli教程,甚至在从git https://github.com/BrentAureli/SuperMario/blob/Mario-Tutorial-26/core/src/com/brentaureli/mariobros/Sprites/Mario.java
中提取代码之后我的角色不跳!即使它左右运行! 所以我注意到LibGDX正在使用新版本,所以我尝试了
private TextureRegion marioStand;
private Animation<TextureRegion> marioRun;
private Animation<TextureRegion> marioJump;
这是构造函数
Array<TextureRegion> frames = new Array<TextureRegion>();
//get run animation frames and add them to marioRun Animation
for(int i = 1; i < 4; i++)
frames.add(new TextureRegion(screen.getAtlas().findRegion("little_mario"), i * 16, 0, 16, 16));
marioRun = new Animation(0.1f, frames);
frames.clear();
for(int i = 1; i < 4; i++)
frames.add(new TextureRegion(screen.getAtlas().findRegion("big_mario"), i * 16, 0, 16, 32));
bigMarioRun = new Animation(0.1f, frames);
frames.clear();
//get set animation frames from growing mario
frames.add(new TextureRegion(screen.getAtlas().findRegion("big_mario"), 240, 0, 16, 32));
frames.add(new TextureRegion(screen.getAtlas().findRegion("big_mario"), 0, 0, 16, 32));
frames.add(new TextureRegion(screen.getAtlas().findRegion("big_mario"), 240, 0, 16, 32));
frames.add(new TextureRegion(screen.getAtlas().findRegion("big_mario"), 0, 0, 16, 32));
growMario = new Animation(0.2f, frames);
frames.clear();
for(int i = 4; i < 6; i++)
frames.add(new TextureRegion(screen.getAtlas().findRegion("little_mario"), i * 80, 0, 16, 16));
marioJump = new Animation(0.1f, frames);
frames.clear();
public TextureRegion getFrame(float dt){
case JUMPING:
// region = marioIsBig ? bigMarioJump : marioJump;
region = (TextureRegion) marioJump.getKeyFrame(stateTimer);
break;
case RUNNING:
region = (TextureRegion) (marioIsBig ? bigMarioRun.getKeyFrame(stateTimer, true) : marioRun.getKeyFrame(stateTimer, true));
break;
答案 0 :(得分:1)
我检查了原始代码,无法在Mario.java
的任何位置找到实际的跳转机制。我可以看看马里奥的垂直速度是否为0
,它应该运行跳跃动画。所以,也许,如果坠落的物理到位并且你从悬崖上跑下来,你会看到跳跃的动画播放。
所以我猜你只需要对角色施加一些力量。类似b2Body.applyForceToCenter(0f,10f,true)
或b2Body.setLinearVelocity(0f, 10f);
的内容。这可以在您检查按键时进入渲染方法,或者如果您使用的是InputProcessor
,则可以使用keyDown
方法。