D
D
djEban2019-05-20 11:43:07
C++ / C#
djEban, 2019-05-20 11:43:07

C#. Which is better: PictureBox or Paint?

In general, I'm making a game in WF where you need to pop the balls rising up. What is better for this: a PictureBox, when clicked with the mouse button, I will teleport it down so that it rises again, or Paint, when clicking on the picture of which a redraw will be performed? And all this on the condition that I need to organize randomly: an arbitrary number of balls will rise, and some will be ahead of others.
PS
Working with Paint in such a game is almost unrealistic. But still, maybe you know how to implement it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Yudin, 2019-05-20
@djEban

I believe that you should first try to display the balls with an image, and if for some reason the pictures did not load, then draw them.
1. Create a variable with an image
2. When initializing the form with the game, we try to load an image into this variable

try
{
    ImageBall = new Bitmap("путь до изображения");
}
catch (Exception ex)
{
    MessageBox.Show(@"Не удалось загрузить: " + ex.Message, @"Ошибка при загрузке изображений!");
}

3. During the balloon generation, we check that the image has loaded, otherwise we draw ourselves
Bitmap bmp = new Bitmap(50,50);
Graphics gr = Graphics.FromImage(bmp);  // это пространство на котором рисуется игра
Rectangle rect = new Rectangle(0,0,50,50); // размер шарика
if(ImageBall == null) // если картинка не загрузилась
{
    gr.DrawEllipse(new Pen(Color.Black), rect); // рисуем круг
}
else
{
    gr.DrawImage(ImageBalls, rect); 
}

5. We place our ball drawn or with a picture in the PictureBox
pictureBox1.Image = bmp

G
GavriKos, 2019-05-20
@GavriKos

Better - canvas, preferably - OpenGL,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question