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

Author Topic: collision between elements in different vectors and classes  (Read 1661 times)

0 Members and 1 Guest are viewing this topic.

AzkaIsHere

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
collision between elements in different vectors and classes
« on: August 15, 2018, 03:39:03 am »
Hello, I have been trying many times to write the collision between the bullet vector and enemy vector of sprites... None were succesful, can someone tell me methods for that?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10988
    • View Profile
    • development blog
    • Email
Re: collision between elements in different vectors and classes
« Reply #1 on: August 15, 2018, 09:35:12 am »
sf::Rect has a function called intersects(), so you can check one sprite against the other by getting their global bounds.

With what are you exactly stuck?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: collision between elements in different vectors and classes
« Reply #2 on: August 15, 2018, 02:19:18 pm »
Do you mean checking all bullets against all enemies?

Use a nested loop to iterate each pair.

(click to show/hide)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

AzkaIsHere

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: collision between elements in different vectors and classes
« Reply #3 on: August 16, 2018, 11:10:00 pm »
I'm sorry I just code for hobby and that results in me being a HUGE noob, I didn't quite understand what I have to do, could you explain please?

 

anything