Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Randomizing the movement of the Sprites  (Read 1311 times)

0 Members and 1 Guest are viewing this topic.

alikroos

  • Newbie
  • *
  • Posts: 3
    • View Profile
Randomizing the movement of the Sprites
« on: April 29, 2024, 02:52:01 pm »
I got an array of Sprites and i wanna make each one of them have different velocity for x and y how could I do such a thing ?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Randomizing the movement of the Sprites
« Reply #1 on: April 30, 2024, 01:59:04 pm »
You'll need to wrap your sprite in an entity, so it can hold a different velocity.
Then you can use <random> to generate random numbers and assign a random velocity to each of your entities.

In the update function, use a delta time step and the set velocity to move your sprites/entities one at a time a bit every frame.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/