Reputation: 1369
I just start libgdx and this looks simple but I don't understand. My render method in screen object will call the render method from WorldRenderer:
public World world;
public void render() {
spriteBatch.begin();
drawBlocks();
drawBob();
spriteBatch.end();
if (debug)
drawDebug();
}
private void drawBob() {
Bob bob = this.world.getBob();
Log.e("inside drawBob",this.world.getBob().getPosition().x +"dadas");
bobFrame = bob.isFacingLeft() ? bobIdleLeft : bobIdleRight;
if(bob.getState().equals(State.WALKING)) {
bobFrame = bob.isFacingLeft() ? walkLeftAnimation.getKeyFrame(bob.getStateTime(), true) : walkRightAnimation.getKeyFrame(bob.getStateTime(), true);
}
spriteBatch.draw(bobFrame, bob.getPosition().x * ppuX, bob.getPosition().y * ppuY, Bob.SIZE * ppuX, Bob.SIZE * ppuY);
// Screen render method
void render(float delta) {
Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
controller.update(delta);
renderer.render();
}
I have a updateBob method to update world's bob position. here is controller 's update :
public void update(float delta) {
processInput();
Vector2 pos = new Vector2(7,7);
//bob.setPosition(pos);
bob.getPosition().x += 1;
bob.update(delta);
}
Application create() method
public void create() {
setScreen(new GameScreen());
world = new World();
renderer = new WorldRenderer(world, true);
controller = new WorldController(world);
//Gdx.input.setInputProcessor(this);
}
Inside the method, I updated it and the value change. but the bob's position in render doesn't change, so I cannot make Bob move. Please tell me where is wrong.
Upvotes: 1
Views: 510
Reputation: 9823
After a discussion in the chat we found the problem. If you override the render()
in your ApplicationListener
, you have to call super.render()
to be sure, that render(float delta)
in Screen
is called. The same should count for pause()
and other methods of ApplicationListener
to.
Upvotes: 1