0

I've been following tutorial once again. Making a flappy bird clone.

According to tutorial i need to create a struct:

    struct Bird
    {
        public float velocityY;
        public float angle;

        public RectangleF bird;

        public Image image;
    }

And then i need to create a method, that suppose to create a instance of that struct:

    private void CreateBird()
    {
        Bird mBird;

        mBird.image = imageBird;
        mBird.velocityY = 0;
        mBird.bird = new RectangleF(Width / 2 - birdWidth, Height / 2, birdWidth, birdHeight);
        mBird.angle = 0;

    }

And here's the kicker.. Nowhere in tutorial its mentioned where you need to put this method.

And for example (obvious but still) I get an error on "mBird.image" when try to do smth like this:

  private void Timer1_Tick(object sender, EventArgs e)
    {
        DoubleBuffered = true;
        Graphics g = CreateGraphics();
        g.Clear(Color.DeepSkyBlue);

        g.DrawImage(mBird.image, 0, 0, 100, 100);
    }

Sow how can you create something like that?

Rufus L
  • 36,127
  • 5
  • 30
  • 43
  • 4
    Sounds like a crappy tutorial. I don't know what you expect us to do about that though. – itsme86 Dec 01 '17 at 21:42
  • 1
    *Where* you declare something defines its `Scope`. Your `mBird` is declared in that void method so that is the only place it exists. Declare it at the form level.... and `CreateGraphics` is almost always the wrong thing to do. Do your painting in the paint event and use the `Graphics` made available to your there. – Ňɏssa Pøngjǣrdenlarp Dec 01 '17 at 21:42
  • This is Winforms. I hoped there is a way to this kind of code at all.. And may be ill be able to figure something out from that point. – Max Saprykin Dec 01 '17 at 21:48
  • declare your `mBird` object at the class level ([the `m` stands for "member"](https://stackoverflow.com/questions/13018189/what-does-m-variable-prefix-mean), after all), so you can access it from both `CreateBird` and `Timer1_Tick` – Rufus L Dec 01 '17 at 21:49
  • This is not an appropriate situation to use a `struct`. Given that the tutorial is trying to get you to do things like this, you should really stop using it and find a better tutorial to use. – Servy Dec 01 '17 at 22:09

0 Answers0