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 / Arrays and GetSpriteCollision.

Author
Message
Yeet
5
Years of Service
User Offline
Joined: 9th Jul 2019
Location:
Posted: 23rd Aug 2019 00:37
Hi, newbie here!

I'm trying to code a part of the game where the player cannot go through the walls. However instead of individually coding to check if the player has collided with ONE wall, I want it to check if the player is colliding with ALL the walls(sprites) in the array.

So for example, this is what my code currently looks like:
if GetSpriteCollision(wall1,Player) or GetSpriteCollision(wall2,Player) or GetSpriteCollision(wall3,Player) ........................
//Collision code goes here!
endif

This is my attempt at trying to include ALL sprites in the array I created:
if GetSpriteCollision(sprites[101] to sprites[110],Player)
//Collision code goes here!
endif

Now, of course the code including the array doesn't work. It works if I only include ONE sprite in the array, but I want it to include ALL of the sprites in the array.

Hope what I've written here makes sense.... I've been trying to work this problem out believe it or not for hours! I'm gonna sleep now. Any help is appreciated! Thanks.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 23rd Aug 2019 02:03 Edited at: 23rd Aug 2019 05:36
To check each element of your array. First of all you need to populate your array with your wall sprites so something like this


Then to check collision something like this;


Hope that helps
Yeet
5
Years of Service
User Offline
Joined: 9th Jul 2019
Location:
Posted: 26th Aug 2019 13:02
Thanks

Login to post a reply

Server time is: 2024-11-23 08:05:10
Your offset time is: 2024-11-23 08:05:10