0
\$\begingroup\$

Is it possible to render a particular object on the screen for a certain number of frames without having to delay the rendering? Thanks

\$\endgroup\$
1
\$\begingroup\$

Indeed it is.

Assuming that your object has a method such as Update() that gets called once per fame, you can simply count your frames and toggle a boolean that you use to determine the rendering.

class Object
{
public:
    bool visible = true;

    void Update()
    {
        frames++;

        visible = frames < 10;  // Or however many frames you want to display the object.
    }
private:
    int frames = 0;
};

// Main loop:
while (True)
{
    HandleEvents()()

    object.Update()

    ClearWindow()
    if (object.visible)
    {
        object.Render()
    }
    UpdateWindow()
}

That is a very basic example of what you might be looking for.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.