Gornova/MarteEngine

Entity currentAnimation setter

Closed this issue · 6 comments

When you set the graphics of an entity it sets the width and height based on the image dimensions(ok)
But when you add an animation then the width and height are not set.

Of course when you add 4 animations then the width and height can be different. In this case the user has to change the width and height when he activates an animation.

Since there is no setter for activating an animation it's not possible to change the width,height there.

Let's add a method in entity

public void showAnim(String animName) {
if (!animations.containsKey(animName)) {
throw new IllegalArgumentException("no animation for " + animName);
}
currentAnim = animName;
width = currentAnim.getWidth();
height = currentAnim.getHeight();
}

or just assume that each animation has the same width,height and set the width when the first animation is added?(tbh assumptions are bad :-)

Yup, good find. Should be improved.
For simplicity certain assumptions are okay, if you add them to the Javadocs for example.
But of course a clever setter who updates width and height would offer more flexibility.

But that's why we are at version 0.2 currently ;-)

You are right! Forgot to handle this case!
Is it in your pull request?

It's not included in my pull request...
Because I would need to add a method.

Can you make a new oull request for this?

done

Entity now has setAnim, solved