The IScalable interface provides an interface for 2D objects which can be resized. IScalable objects have two properties which control size:
Note: By default, scale has nothing to do with the Texture that an object is displaying. Two objects showing different Textures of different dimensions will be the same size if they have the same scale values.
What is Scale?
Scale defines the distance from the center of an object to its edge.
Scale values are used used instead of “width” and “height” because it simplifies collision and object placement.
In other words, the following relationships exist:
ScaleX = Width / 2; ScaleY = Height / 2;
Width = ScaleX * 2; Height = ScaleY * 2;
The following code creates 3 Sprites with different scales.
Sprite regularSizedSprite = SpriteManager.AddSprite("redball.bmp"); regularSizedSprite.Y = 4; Sprite scaledOnXSprite = SpriteManager.AddSprite("redball.bmp"); scaledOnXSprite.ScaleX = 3; Sprite scaledOnXAndYSprite = SpriteManager.AddSprite("redball.bmp"); scaledOnXAndYSprite.Y = -7; scaledOnXAndYSprite.ScaleX = 3; scaledOnXAndYSprite.ScaleY = 3;
Scale is independent of Texture
The ScaleX and ScaleY values on objects such as Sprites is (by default) independent of the Sprite’s Texture property. Therefore, if two Sprites both have the same ScaleX and ScaleY values, they will appear as the same size on screen regardless of the size of the Textures that they are displaying.
- Understanding the 3D Camera tutorial – Information on Scale and it’s relationship to on-screen size
- Setting a Sprite to Pixel Size – Shows how to set a Sprite’s scale so that it appears the same dimensions as its source Texture.
- Justifying IScalables
- FlatRedBall.Graphics.Model.PositionedModel.ScaleX – Scale and PositionedModels.
Did this article leave any questions unanswered? Post any question in our forums for a rapid response.