Note that there are some explanatory texts on larger screens.

plurals
  1. PODrawImage() 'sprite' not showing up
    primarykey
    data
    text
    <p>I'm attempting to use a custom built .PNG file of letters from the alphabet to give my game some nice looking textual graphics. However, since the core functionality of my WinForms game works using minimal graphics (I have a timer set to fire a little animation routine that fades out the word "Guessed" when a user enters a word that they've already tried - this is done using DrawString()). Right now I'm trying to get <code>DrawImage(Image, dstRect, srcRect, Unit)</code> to work, and I have it set to run on form load. </p> <pre><code> private void DrawLetters() { // Create image. Graphics letters = this.CreateGraphics(); Image newImage = Image.FromFile(strPath + "Letter_Map.png"); // Create rectangle for displaying image. Rectangle destRect = new Rectangle(25, 25, 80, 80); // Create rectangle for source image. Rectangle srcRect = new Rectangle(0, 0, 833, 833); GraphicsUnit units = GraphicsUnit.Pixel; // Draw image to screen. letters.DrawImage(newImage, destRect, srcRect, units); } </code></pre> <p>This is practically verbatim from the MSDN site. My form populates with an array of Labels right now to show the user the grid of letters needed for the game. Is it them being drawn that overwrites the custom rectangle? I want to replace them all with images eventually. I understand srcRect to be (x, y, width, height) so I gave it the full size of the 'spritesheet'. For dstRect I only want it to place a block 80x80px on the form starting around 25x, 25y.</p> <p>For the heck of it I created a blank form and called my <code>DrawLetters()</code> function during that form load event (I copied the function into that Form's code). I saw nothing, though, so I am starting to get a bit confused. I may need some education about just HOW the drawing works in conjunction with forms and controls being drawn on screen.</p> <p><strong>EDIT</strong> This <a href="https://stackoverflow.com/questions/837423/render-a-section-of-an-image-to-a-bitmap-c-sharp-winforms" title="question here">https://stackoverflow.com/questions/837423/render-a-section-of-an-image-to-a-bitmap-c-sharp-winforms</a> was what initially got me going, but this user has a working knowledge of XNA and seems to be trying to combine that with WinForms. XNA would be overkill, I believe, for the simple text game I am trying to 'pretty up'.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload