Gornova / MarteEngine

MarteEngine is a Java Engine for videogames
http://randomtower.blogspot.com
Other
74 stars 20 forks source link

width, height -> private #82

Closed Stef569 closed 12 years ago

Stef569 commented 12 years ago

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 =)

jvanbaarsen commented 12 years ago

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.

Stef569 commented 12 years ago

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

jvanbaarsen commented 12 years ago

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.

Stef569 commented 12 years ago

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.

Stef569 commented 12 years ago
/** 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?

jvanbaarsen commented 12 years ago

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..

Stef569 commented 12 years ago

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.

jvanbaarsen commented 12 years ago

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

Stef569 commented 12 years ago

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