Sprite.Draw

Using the December 2005 SDK

How do i scale a texture to be drawn to the screen on a sprite

MDX 1.x had Sprite.Draw2D(...) which took a destinationRectangle.



Answer this question

Sprite.Draw

  • Bard7

     

    The draw2d call is still included in the 1.1 assemblies, but in the MDX 2 system the draw2d has been removed. If you look in the simple2d sample from the sdk, there is an example of drawing sprites using both the Draw2d method and the draw method.

    Here is the small code sample from the sprite containers code file.

    /// <summary>

    /// This draw call example is not used in the sample, but is provided to show

    /// how to emulate the Draw2D call by setting the transformation property.

    /// before the Draw() call.

    /// </summary>

    public void DrawAlternate(Sprite sprite)

    {

    Matrix transformation =

    //First, translate to the center of the original (untransformed) sprite

    Matrix.Translation(-srcRect.Width / 2f, -srcRect.Height / 2f, 0f)

    //scale the sprite

    * Matrix.Scaling(spriteWidth / srcRect.Width, spriteHeight / srcRect.Height, 1)

    //rotate about the z axis (into the screen) of the centered sprite

    * Matrix.RotationZ(direction)

    //translate to the final position

    * Matrix.Translation(position.X, position.Y, 0);

    //set the transformation

    sprite.Transform = transformation;

    //Draw with position 0, center 0, and color white (all needed transformation has been completed at this point)

    sprite.Draw(tex, srcRect, Vector3.Empty, Vector3.Empty, Color.Red);

    }



  • Sprite.Draw