C# Mehrere bewegte Bilder (z.B. Pictureboxen) die sich verändern?

1 Antwort

Vom Fragesteller als hilfreich ausgezeichnet

Eine möglichkeit wäre, statt nen Haufen PictureBoxen eine einzige PictureBox zu nehmen, das ganze "Rendering" auf einem System.Drawing.Bitmap durchzuführen und dann der PictureBox dieses als "Image" zuzuweisen.

Im Grunde also etwas in der Art:

public struct Ufo{
public Bitmap Bitmap;
public int X, Y;
}
public struct Comet{
public Bitmap Bitmap;
public int X, Y;
}
public class DaGame{
private Ufo ufo;
private List<Comet> comets;
public DaGame(){
ufo = new Ufo(){Bitmap = new Bitmap("ufo.png"), X = 0, Y = 0};
comets = new List<Comet>();
}
void RenderFrame(Bitmap frame){
Graphics g = Graphics.FromImage(frame);
g.DrawImage(ufo.Bitmap, ufo.X, ufo.Y);
foreach(Comet comet in comets){
g.DrawImage(comet.Bitmap, Comet.X, Comet.Y);
}
}
}

P.S.: Das ganze ist nur eine Art grobe Vorlage, mit ein bisschen Arbeit dürfte das allerdings funktionieren... Und zwar nicht unerheblich schneller als mit nem Haufen PictureBoxen...


JaskiHax 
Fragesteller
 15.04.2017, 10:02

Okay danke, hatte auch schonmal daran gedacht, werde das in ein Panel rendern.

0