Hi, guys! Just joined up after lurking for a while. I have limited programming experience, so please bear with me :)
I'm trying to build a simple C# game for my mobile phone, so I'm using .net CF 3.5 on my Touch HD (WM 6.1). The basic game works, but now I'm trying to add a score counter using numbers from a texture sheet I made.
Looking around, this should be simple: just use an e.Graphics.DrawImage() call in the counter's OnPaint (the counter is a custom controll derived from UserControl), using the (bitmap, destRect, scrRect, gfxUnit) overload. This should do the trick and MSDN tells me this call is supported in CF 3.5.
Everything seems to work (the incrementing to change the scrRect to crop the number I want, the placement of the counter), but for some reason the actual bitmap-part won't show! It just displays the background :(
Oddly enough, to troubleshoot, I placed a
"e.Graphics.Clear(Color.Beige);"
just above the DrawImage() in the control's OnPaint, and now, exactly where I would want to see a nice bit of bitmap containing my cropped number, I see a beige box :(
Here's the counter class:
sing System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Drawing;
namespace Mash2
public class SideScrollScoreBox : System.Windows.Forms.UserControl
{
//vars
public Bitmap scoreSheet;
public Rectangle bitmapPart;
public Rectangle locRect;
//accessors
protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e)
{
//Do nothing
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.Clear(Color.Beige);
e.Graphics.DrawImage(scoreSheet, locRect, bitmapPart, GraphicsUnit.Pixel);
}
//constructors
public SideScrollScoreBox(Bitmap scoreSheet)
{
this.scoreSheet = scoreSheet;
}
}
}
One of the counters is initialised like so (in the form):
private static Bitmap blueNumbersJ = new Bitmap(@"Program Files\\Mash2\\jpgs\\numbersheet_blue.jpg");
public SideScrollScoreBox redScoreBox = new SideScrollScoreBox(redNumbersJ);
with it being set up further in a method DrawBackground():
//define lower picbox scoreboard
//SideScrollScoreBox redScoreBox = new SideScrollScoreBox(redNumbersJ); //done as public static uptop
redScoreBox.Location = new Point(23, 703);
redScoreBox.Size = new Size(70, 70);
redScoreBox.bitmapPart = new Rectangle(0, 0, 48, 64);
redScoreBox.locRect = new Rectangle(redScoreBox.Location.X, redScoreBox.Location.Y, redScoreBox.Size.Width, redScoreBox.Size.Height);
this.Controls.Add(redScoreBox);
this.Controls.SetChildIndex(redScoreBox, 4);
redScoreBox.BringToFront();
There's some logic to move along the .X of bitmapPart, but that seems to work fine. The problem is that the DrawImage() call doesn't seem to work. Is this a known problem (ie cf3.5 can't crop images, despite what MSDN says) or am I doing something dramatically wrong?
PS: how do you get those nice codeboxes? <code></code> just doesn't look as nice!