1

I just started learning Raylib, and I'm trying to create something like the drawing example that they have on the website, but its not working for me. I want to click on R and spawn/draw objects on screen but the object disappears once I release the button,

if (IsKeyDown(KEY_R)) {
    DrawRectangleV(SpawnRecPos, RecSize, RecClr);
}

Is there is a way to store the data when I click so that the rectangle stays on the screen?

Dada
  • 6,313
  • 7
  • 24
  • 43

1 Answers1

0

If you're using c++, it's probably the easiest to use std::vector for this. You can create one with Raylib's Vector2 type, which has just an x and y component. Then you just add to that std::vector using
MyVector.push_back(GetMousePosition());
whenever R is held (GetmousePosition is one of raylib's functions that returns the mouse position as a Vector2 type). Then when you want to draw the shapes you just loop over that vector and use one of raylib's shape drawing function to draw some shape at those positions.

Shunya
  • 2,344
  • 4
  • 16
  • 28
Qruintrox
  • 1
  • 2