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

Author Topic: How to randomly generate sprites  (Read 19527 times)

0 Members and 1 Guest are viewing this topic.

WDR

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
Re: How to randomly generate sprites
« Reply #15 on: August 01, 2013, 08:59:25 pm »
Come on, guys... Nothing? Please Help!!!  :(

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: How to randomly generate sprites
« Reply #16 on: August 01, 2013, 09:06:17 pm »
Sorry, we're not here to program your game.
I've explained everything in detail and some have given you code pieces, if that's not enough, then made you're not ready for that kind of programming?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

WDR

  • Jr. Member
  • **
  • Posts: 82
    • View Profile
Re: How to randomly generate sprites
« Reply #17 on: August 01, 2013, 09:49:48 pm »
I didn't ask for code. I asked for theoretical solutions. But no one responded to that either.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: How to randomly generate sprites
« Reply #18 on: August 02, 2013, 12:16:42 am »
I didn't ask for code. I asked for theoretical solutions. But no one responded to that either.

I will respond to your questions without code, but before I do you need to understand what you are asking is basic C++ knowledge. That is why I highly recommend you pickup a good C++ book and get the bases down before you try game programming. Trying to learn C++ and game programming at the same time will cause you to learn questionable coding habits.

1) All sprites are generated randomly but they all appear at once. They should appear one after the other with a fixed time interval. How do I set that condition?

There is no "condition" you can just set, this is where knowledge about computer programming comes in. What you must do is track the total elapsed time from every frame and when it exceeds your time interval subtract your time interval from the total elapsed time and spawn a new sprite.


Quote
2) The maximum number of sprites generated is the maximum size of the array. Is there any other method where indefinite number of enemies are generated until the player dies or the game is stopped?

To start off std::vector<t> is not a fixed array. You can put as many elements into it as you want (until you run out of memory). So just keep spawning (as I explained above) until you wish to stop.


Quote
3) I've set bounding box collisions and collision conditions for the enemy sprites in a similar fashion using vector arrays, but I'm pretty sure that's wrong because it doesn't work. They overlap each other, and do nothing when they collide with the player. How do I randomly generate them such that they don't overlap each other and they collide with the player?

Do not use another vector for bounding boxes. There is nothing magical that will update your second vector bounding boxes with what you applied to your sprite. Just your existing vector of of enemies and call sf::Sprite.getGlobalBounds() to get the bounding box of the sprite. As for collisions use sf::Rect.intersects(xxx) to determine if bounding boxes intersect.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

 

anything