[GREENFOOT-212] Remove Actor.getWidth() and Actor.getHeight
The methods to get the width and height of an Actor are not very useful, and they are difficult to define the behaviour of when the actor is rotated, the cellsize is bigger than 1x1. The email that initiated this decision:
If the cell size is 1x1, and an actor's image has an even width/height, the Actor's methods getWidth() and getHeight() reports a size as one bigger than the size of the image.
This is the result of some recent changes to collision detection code. It used to give the size of the image.
The current behaviour can be considered to be correct according to the definition of getWidth and getHeight, since they are defined as returning the number of cells the actor covers. For example, if an image of width 2 is considered to have it's center in the middle of the pixel, then it will have 1/2 pixel covering the cells on both sides, giving it a size of 3.
But, I don't think that behaviour is very useful. I found the bug while testing some of the scenarios from Greenfoot gallery, where getWidth/getHeight is used for pixel-level image manipulation. This then fails with an index out of bounds when iterating through the pixels. Strictly speaking the size of the image should be used for this and not the size of the actor. When considering a rotate Actor, this completely breaks for instance (because rotation is considered when calculating the width and height)
The only other reason I can think of for using getWidth and getHeight is to figure out the corners (top-left usually) of an Actor, in order to place the actor relative to its corner instead of the center (often used for displaying text).
Can anyone think of other uses for Actor's getWidth and getHeight? Has anyone ever used it for a scenario where the cell size is greater than 1x1?
If not, then maybe we should consider removing the methods and encourage using a combination Actor.getImage().getWidth/Height() and World.getCellSize() instead.
Issue metadata
- Issue type: Task
- Priority: Medium
- Fix versions: 1.5.0