Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Physics collision checks on multiple sprites

Author
Message
wargasmic
18
Years of Service
User Offline
Joined: 15th Oct 2006
Location: UK
Posted: 14th Feb 2014 19:11
I\'m currently using GetPhysicsCollision(player, ground). As I only have a single sprite to represent the ground for now though, this makes sense.

What happens though when I have multiple (possibly hundreds) of sprites that I want to perform the same bit of code on whenever there\'s a collision?

Do I have to index all my sprites into an array then loop through and manually perform the collision check for each sprite (i understand this is the usual way, just thought AppGameKit might have something in place to avoid indexing everything), or is there any way to check for collisions between, say my player and a category? Something like...

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 14th Feb 2014 19:29
maybe use this, you get a list of sprites that collide with ground.
GetSpriteFirstContact ( iSprite1 )
GetSpriteNextContact ( )
GetSpriteContactSpriteID2 ( )
GetSpriteContactWorldX ( )
GetSpriteContactWorldY ( )

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Feb 2014 20:26 Edited at: 14th Feb 2014 20:29
Something like this maybe?


If you just want to do the same routine for any sprite that hits the player then you won't need the array like I do. But since I have multiple types of sprites that can collide, I need to know which is which.

An alternative approach I just thought of eliminates my immediate need for the array and extra function. Since I only have 1 player sprite and only 1 bullet and the rest are asteroids, I can do the following:




If I did have multiple bullets, then if they used the same image I could then do:


wargasmic
18
Years of Service
User Offline
Joined: 15th Oct 2006
Location: UK
Posted: 17th Feb 2014 19:46
Thanks guys.

Looks like I'll have to go the traditional route as I will be adding multiple types of objects to the game now.

Thanks for the suggestions
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 18th Feb 2014 14:19
Have you looked at PhysicsRaycast? I reckon that would be the best solution. You could add all of the ground sprites to 1 group and then perform a raycast check against that particular group. This is what I do for my platform game to ensure the player can only jump when in contact with the ground...

Much easier than performing a collision check against every ground sprite. You can also use this raycast for other things too, for example, in my case, checking the player has jumped on an enemies head...
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Feb 2014 14:22
Agreed, raycasting is a better way to do this.

oct(31) = dec(25)

Login to post a reply

Server time is: 2024-11-25 01:31:23
Your offset time is: 2024-11-25 01:31:23