Game Development Reference
In-Depth Information
We start by setting the weapon and the weapon's target distance. This is simply
used for the Z value when we call the Canvas.SetPosition() function in our
next set of code. We also set the crosshair size through a number of factors. Our
crosshair scaling float is defined in our defaultproperties block; it's currently
set to 1 . We then multiply it by the crosshair coordinates (also defined in the
defaultproperties block), and again by the canvas size.
The screen dimensions are then set after that. The Y and X values are set to half of
the screen clipping size. The screen clip essentially determines where the edges of
the screen are. Cutting this in half lets us know where the middle of the screen is.
Finally, we set ScreenX and ScreenY to be our previous value, minus half of the
crosshair size. This finds the center point of our crosshair.
3.
Let's add the second half of the function as shown in the following code:
if ( CrosshairImage != none )
{
/** Draw crosshair drop shadow */
Canvas.DrawColor = BlackColor;
Canvas.SetPos( ScreenX+1, ScreenY+1, TargetDist );
Canvas.DrawTile(CrosshairImage,CrosshairSize.X,
CrosshairSize.Y, CrossHairCoordinates.U,
CrossHairCoordinates.V, CrossHairCoordinates.UL,
CrossHairCoordinates.VL);
/** Draw crosshair */
CrosshairColor = Default.CrosshairColor;
Canvas.DrawColor = CrosshairColor;
Canvas.SetPos(ScreenX, ScreenY, TargetDist);
Canvas.DrawTile(CrosshairImage,CrosshairSize.X,
CrosshairSize.Y, CrossHairCoordinates.U,
CrossHairCoordinates.V, CrossHairCoordinates.UL,
CrossHairCoordinates.VL);
}
We're going to draw our crosshair twice in this example. The first time is to add a nice
drop shadow to the crosshairs by offsetting our values by one pixel and shading the
crosshair black.
In the next step, we draw the actual crosshair which we will see. Our Drawcolor
parameter is defined in our defaultproperties block. We are setting the position
to be the center of the screen, and using the CrosshairImage (also defined in the
properties block) as the texture to be drawn.
 
Search Nedrilad ::




Custom Search