I'm a rookie at C# and WPF and I'm trying to create a simple car-simulator. Mainly the idea of the simulator is that I have C#-class that creates car-objects that have for example speed variable that can be changed and timer for moving from left to right. I want to do movement with timer and not for example doubleanimation
. In WPF I have AddCarButton for adding cars in certain points in Canvas.
The problem is I dont know how to add cars to Canvas. This is very frustrating because it doesn't sound like a big thing to do but I feel like I have tried everything and not succeeded.
This is latest attempt with car-class. I have tried using Canvas.Set-methods but failed.
class car
{
private int speed;
public car(int s)
{
speed = s;
Bitmap bmp = new Bitmap(
System.Reflection.Assembly.GetEntryAssembly().
GetManifestResourceStream("MyProject.Resources.car.png"));
Graphics g = Graphics.FromImage(bmp);
//Canvas.SetBottom(g, 0);
//Canvas.SetLeft(g, 0);
//Canvas.SetBottom(bmp, 0);
//Canvas.SetLeft(bmp, 0);
}
public void addCar(car c)
{
Canvas.SetBottom(c, 0);
Canvas.SetLeft(c, 0);
}