Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
General
»
collision between elements in different vectors and classes
Print
Pages: [
1
]
Author
Topic: collision between elements in different vectors and classes (Read 1665 times)
0 Members and 1 Guest are viewing this topic.
AzkaIsHere
Newbie
Posts: 25
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?
Logged
eXpl0it3r
SFML Team
Hero Member
Posts: 10989
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?
Logged
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.
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)
for
(
auto
&
bullet
:
bullets
)
{
for
(
auto
&
enemy
:
enemies
)
{
bool
isColliding
{
checkForCollision
(
bullet, enemy
)
}
;
}
}
Logged
Selba Ward
-SFML drawables
Cheese Map
-Drawable Layered Tile Map
Kairos
-Timing Library
Grambol
*
Hapaxia Links
*
AzkaIsHere
Newbie
Posts: 25
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?
Logged
Print
Pages: [
1
]
SFML community forums
»
Help
»
General
»
collision between elements in different vectors and classes
anything