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.

Newcomers AppGameKit Corner / AGK V2 Tier 1. Put sprites into a group

Author
Message
shedz
5
Years of Service
User Offline
Joined: 23rd Dec 2014
Location: England
Posted: 5th Feb 2015 13:34
Hi

can we put sprites into a group, and give the group properties which would be inherited by the sprites in that group? Or even just set the sprite properties for the group members individually, but then be able to react on collisions with any sprites in the group by a sprite outside of that group (the player).

SetSpriteGroup doesn't do what I'm after, as far as I can work out anyway.

This is needed (well would be nice) for a platformer game. I could have a ground sprite, and several platform sprites in a group. Give the group some properties. Then I could check if the player object collides with the ground/platform objects by checking if the player has collided with the group object.

Otherwise, I'm going to have to check for collisions with each individual platform, plus the ground, which would make some rather big 'if' statements.

Thanks
Nick .
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Feb 2015 14:26
You have the command GetSpriteHitGroup() which will check for collisions within a specific group.

For additional group properties, I would suggest an array of a user-defined type. For a dozen or so groups this would be efficient enough.

Quidquid latine dictum sit, altum sonatur
shedz
5
Years of Service
User Offline
Joined: 23rd Dec 2014
Location: England
Posted: 6th Feb 2015 19:18
Thanks BatVink, that does work. However, there seems to be an issue with the GetSpriteHitGroup() function, it expects a sprite group ID, and X position and a Y position.

The X and Y position are exact points on the screen, while the player sprite is bigger than a single point, so in my case I only allow the Player to jump if he's on the ground or on a platform, both of which are in the sprite group.

If the player is half off the end of a platform, the point I've specified may not be actually colliding with the platform, so the Player can't jump.

This code should help explain it

This function is called in the game loop, the id parameter is the Player.



Any feedback/help appreciated, thanks.
BatVink
Moderator
16
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Feb 2015 12:33
You can set which groups can collide with each other, and then use standard physics collisions. Would that work? For example, you can say that the player group (just one object in the group) can collide with the platform group, but ignore the background sprite group.

I did this in a bingo game, where 50% of the balls collided just with each other, and the other 50% collided in a separate group. It gave me a nice effect of the bingo balls being at different depths. There were 90 balls shooting around at high speed and performance wise it had no problems at all.

Quidquid latine dictum sit, altum sonatur
Funnell7
8
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 7th Feb 2015 21:23
An alternative (and how I've done it in my platform game), is to use PhysicsRaycast... I cast a ray just under my characters feet (at the back and front) and use the PhysicsRayCastGroup( group, x, y, x2, y2 ) command to detect whether the character is touching the ground (I give the ground/platform sprites their own group)...

Using AppGameKit V2 Tier 1
Zolarius
12
Years of Service
User Offline
Joined: 8th Jul 2007
Location: Vancouver, WA USA
Posted: 6th Mar 2015 08:01
Hey Shedz,

No expert advice here -- still learning. However, on an older
program called The Games Factory they had a demo program called
ZEB. In that plat former they used invisible sprites as detectors.
Some would detect if you were approaching and would then activate
a sentry guard to begin firing in your direction. Others were designed to detect contact which would allow you to hang by one
arm from the edge of a platform.

Just a thought that might help you! Good Luck!

Zolarius

Full time contractor -- Struggling programmer since 1985!
Many ideas and no completions yet! Hoping AppGameKit will solve that for me. Thanks TGC and members for your support.
JHA
16
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 7th Mar 2015 01:33 Edited at: 7th Mar 2015 01:40
Hello Shedz,

I made a physics based platformer that uses sprite groups like you want to.

I'm not the greatest coder and it isn't fully completed, but it should help to get you in the right direction.


Here is the full source code: (I have attached the code and media too)



I hope it helps and let me know if you have any questions.

Thank you
JHA

Proverbs Challenge: http://pc.potentialsunleashed.com/

Using AppGameKit V2 Tier 1 - FPSC Reloaded / Game Guru

Attachments

Login to view attachments

Login to post a reply

Server time is: 2020-02-20 09:40:20
Your offset time is: 2020-02-20 09:40:20