ScoreZoom.cs
to the Game1 class. using
directive to the top of the file:using Microsoft.Xna.Framework.Graphics;
public string Text; public Color DrawColor; private int displayCounter; private int maxDisplayCount = 30; private float scale = 0.4f; private float lastScaleAmount = 0.0f; private float scaleAmount = 0.4f;
Scale
read-only property to the ScoreZoom class:public float Scale { get { return scaleAmount * displayCounter; } }
public bool IsCompleted { get { return (displayCounter > maxDisplayCount); } }
public ScoreZoom(string displayText, Color fontColor) { Text = displayText; DrawColor = fontColor; displayCounter = 0; }
Update()
method to the ScoreZoom class:public void Update() { scale += lastScaleAmount + scaleAmount; lastScaleAmount += scaleAmount; displayCounter++; }
The ScoreZoom class holds some basic information about a piece of text and how it will be displayed to the screen. The number of frames the text will be drawn for are determined by displayCounter
and maxDisplayCount
.
To manage the scale, three variables are used: scale
contains the actual scale size that will be used when drawing the text, lastScaleAmount
holds the amount the scale was increased by during the previous frame, and scaleAmount
determines the growth in the scale factor during each frame.
You can see how this is used in the Update()
method. The current scale is increased by both the lastScaleAmount
and scaleAmount. lastScaleAmount
is then increased by the scale amount. This results in the scale growing in an exponential fashion instead of increasing linearly by a scaleAmount
for each frame. This will give the text a zooming effect as it starts growing slowly and then speeds up rapidly to fill the screen.
3.145.163.58