Gornova/MarteEngine

After changing an animation, everything brokes

Closed this issue · 6 comments

I'm trying to change an animation when two entities collide, with no luck so far.

I basically check in the Player class if a collision occurs, then I proceed to change the current animation on that entity, as shown here:

public void moveDown() {
    if (collide(colisionables, x, y + mySpeed.y) == null) {
        y += mySpeed.y;
    }
    if (collide(ABloque.NPC, x, y + mySpeed.y) != null) {
        collide(ABloque.NPC, x, y + mySpeed.y).currentAnim = "STAND_UP";
    }
}

But then, the Classroom class, that extends World, throws a NullPointerException when calling the super method:

@Override
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
    super.render(container, game, g);
}

There, in the only line my render method has the game brokes. i've tryed catching the exception and everything just dissapears.

What I want to achieve with this is that NPCs face the player when they collide. Maybe I'm doing it wrong and there is a easier way, I don't know...

I'm using Marte Engine 0.3 dev version, the same library inside the Rogue Like examples in Gornova's blog.

Edit:

I also tried collisionResponse to no avail:

@Override
public void collisionResponse(Entity other) {
    if (other instanceof NPC) {
        NPC npc = (NPC) other;
        npc.currentAnim = "STAND_LEFT";
    }
}

Deses, in 0.3 this code
collide(ABloque.NPC, x, y + mySpeed.y).currentAnim = "STAND_LEFT"

does not compile anymore, you should use setAnim("STAND_LEFT") instead.
See https://github.com/Gornova/MarteEngine/blob/dev/src/it/marteEngine/entity/Entity.java#L330

thanks Stef for answer

Oh my, I forgot to comment this after closing the issue...

Well, as Stef said, that it the correct way to do it, I figured it out after some time looking at the code, and I ended by downloading the repo and compiling the 0.3 library, because I was using 0.2 or an unfinished version of 0.3, dunno.

Anyway, the project is now finished and handed to my teachers, who loved it.

Thanks a lot for this handy library!

hey, send me a pm about your project, I'm curious

Here it is:

https://github.com/Deses/PokeDAI/downloads

It's a short game, in homage of Pokémon to learn how a game works, not a serious game. xD

nice game dude