Gornova/MarteEngine

width, height -> private

Closed this issue · 9 comments

Since the width and the height are equal to the size of the current image or animation frame they should be private and only assigned in the setGraphic and setAnim methods.

public class Block extends Entity {
public Block(float x, float y, int w, int h) throws SlickException {
super(x, y);
addType(SOLID);
setHitBox(0, 0, width, height);
name = "solid";
}

width and height are set because setHitbox assigns them ?

public class Block extends Entity {
public Block(float x, float y, int w, int h) throws SlickException {
super(x, y);
name = "block";
depth = 5;
currentImage = ResourceManager.getImage("block");
}
}

width and height are 0 because currentimage is directly assigned, should of used the setGraphic method.

I guess there is 2 ways to solve this:
/** static image for non-animated entity, USE SETGRAPHIC(Image) TO SET THIS VALUE */
public Image currentImage;

/**
 * width of the entity. not necessarily the width of the hitbox. Used for
 * world wrapping, DON'T OVERWRITE THIS VALUE
 */
public int width;

or just
/** static image for non-animated entity /
private Image currentImage;
/
* the width of the entity, really... */
private int width;

So that everybody will use the setter. This is why we use java right =)

Dont agree, the width and height is not always equal to the image.. I think there need to be some sort of getter/setter system so you can alter the values when you need to.

Could you give an example when the width/height is not equal to the image, and how you would use those values?

Well, if the entity is not based on an image.. Maybe just created using g.fillRect() or something like that..Or maybe you have a simple shadow in your image, this means that the stuff of the image you use is smaller then the actual image.

Aha! So the width and the height are the dimensions of the entity as it appears on the screen. When you create an entity with an image the width and height are set to the image dimensions. If you use fillRect you choose your own with and height. Ok makes sense... they can be public then.

/** Block */
public class Block extends Entity {
  setGraphic(ResourceManager.getImage("ship"));  // entity width/height == ship dimensions[30,30]
  setHitBox(8, 5, 20, 20); // Make the hitbox of the ship a bit smaller
}

Should the entity assign the width/height based on the hitbox?

I dont think the width / height should be assigned automatically.. Create a setter for the width and height, so the developer is responsible for the assignment of those values..

Entity should help where it can,

The width and the height are the visible dimensions of the entity as it appears on the screen...

If you set an Image then entity knows what the width and height are.

The hitbox should not change the width and height because that's not visible.

and you can always overwrite the width and height.

Ok, as long you can always manually set / overwrite the width and height there is no problem.

width and height are set when using setGraphic(Image) or setAnim(String) you can always overwrite them(they are still public) setHitbox does not change the width/height. in the Dev branch. thx for the insights jvanbaarsen