Game Development Reference
In-Depth Information
CreateRotationX(math::HalfPi);
There are a few more things to consider other than just how to draw a damage indicator
sprite,andtheywilllargelydependonthegame'sartisticdirection,forthisexampleweuse
a duration field to define the lifetime of the damage indicator, each frame we will decre-
ment this duration by deltaTime and when it reaches zero, we remove the indicator from
the m_indicators list. The color of each indicator is hard coded to red, this should be con-
figurablefromsomeexternalsource,anditwilldependentirelyonthegame,damagecolor
could be derived from the type of damage, or the damage intensity, also to keep the ex-
ample simple we don't animate the color, but we could interpolate the alpha based on life-
time of the indicator to make it fade in, then out.
Now let's look at the Draw function:
auto device = m_core->GetDevice();
auto viewport = device->GetViewport();
DirectX::CommonStates states(device->GetDevice());
m_spriteBatch->Begin(DirectX::SpriteSortMode_Deferred, states.Additive());
for (auto& it : m_indicators) {
const math::vector2& direction = math::vector2(it.direction.x(), it.direction.z());
math::point p = m_ellipse.GetPointOnEllipse(direction);
auto screenPoint = math::vector3(p.x() + viewport.Width()/2, p.y() + viewport.Height()/2, 1.f);
m_spriteBatch->Draw(*m_texture->GetView(),
math::vector2(screenPoint.x(), screenPoint.y()), nullptr, it.color, it.angle, math::vector2(m_texture->Width()/2, m_texture->Height()/2));
}
m_spriteBatch->End();
We iterate over the list of indicators that we have accumulated during a frame, each indic-
ator is an instance of damage received, the first thing we do it query the ellipse for a point
ontheellipsegivenadirection(thisiscoveredindetailinthesectionaboutellipse)wewill
then offset the point so that it is centered around the viewport. Finally we draw the sprite,
the Draw function allows us to provide a rotation angle and an offset within the sprite to
use as the rotation pivot, we set the angle to the one we calculated when we received the
damage direction (Ɵ+δ) and the pivot point will be the center of the sprite's texture.
Search WWH ::




Custom Search