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.

2D All the way! / Sprite Collision (In con-junction with Ian's code)

Author
Message
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 26th May 2003 20:45 Edited at: 26th May 2003 20:46
Hi, Ian (or anybody..) I have finally got around to using your sprite (alpha) collision function code, however I do not know exactly how to set it up and use it, for example, I think I have used it right, but don't know how to show this in my code, e.g. message popping up stating the sprites have collided, or the background changing a colour, anything just to show the sprites have colided..

in the code tag is Ian's code, and in the source button is my code, if you could just alter my code, or show me an example that performs the aforementioned then I would be most grateful.

Thanks in advance Ian/People.
-Nilrem



P.S.
The images can be found at:
http://www.grinders.withernsea.com/ar/spaceship1.bmp

and

http://www.grinders.withernsea.com/ar/bullet_50x50.bmp

I hear and I forget. I see and I remember. I do and I understand.
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 27th May 2003 18:01
Help?

I hear and I forget. I see and I remember. I do and I understand.
Flashing Blade
21
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 27th May 2003 21:42
i never used it in a game but i tried it a while back and,i think the function returns '1' if the two sprites passed to function have pixels touching.

But i *think* it might not work if your sprite is flipped/mirrored/rotated.

do this with Ian's function:


in my game i got lots of sprites that are mirrored/rotated/flipped etc
so what i did was this:

break the image up into SQUARE/RECTANGULAR CHUNKS
take note of the x/y offsets of those chunks
color those chunks black & save 'em (i colored white whilst testing)
now use the black chunks as sprites on top/under proper sprite and check these for collision

now i'm in process of optimizing my code and using types instead of sprites for my collision boxes.
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 28th May 2003 01:46
Flashing blade could you please possibly include that in conjunction with my code please?

Sorry to be a pain mate.

I hear and I forget. I see and I remember. I do and I understand.
Flashing Blade
21
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 28th May 2003 13:22
you use same as DBP's sprite collision function.

But i just tried it and i can't get it working right. This probably because Ians code was written pre patch3.1

anyway heres the function in your code:

oh if you meant incorporate my collision boxes methods into your code just say and i'll do you an example.
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 29th May 2003 17:01 Edited at: 29th May 2003 17:03
What I want is pixel accuracy collision, but when I try sprite hit (on my space invaders project) it counts from the blackness of the object hitting the blackness of the other project, not the actual coloured image.. for example two objects |- and -| should collide like this |--| but instead always seem to collide like this
|- -| (depending on the image size, 50x50 for example) is this making sense? Do you or anyone else know how to make the collision accurate? (I'm using 2D not 3D)

I hear and I forget. I see and I remember. I do and I understand.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th May 2003 17:21
My test code for the sprite collision works great - I just can't seem to get it working with your code.

I'll try to work it out for you though.
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 29th May 2003 21:40
Any idea what the problem is Ian? Does anyone know the problem/solution?

I hear and I forget. I see and I remember. I do and I understand.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th May 2003 21:51
Heh, that's the problem with highly optimising code - it's too difficult to fix when it breaks

Anyway, here's a slightly slower version that does work with your images.
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 31st May 2003 13:52
I'm not quite sure how to use that with my source, I'm used to using gosub's, could you please possibly tell me how, or show me how by using it in my code?

I hear and I forget. I see and I remember. I do and I understand.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 31st May 2003 14:10
Sure
Nilrem
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: United Kingdom
Posted: 1st Jun 2003 16:35
You would't believe my face right now!! So lightened up, thankyou so so so much Ian!!

Calm down Jamie... G.C.S.E Science test tomorrow and you only began revising for it today...



I hear and I forget. I see and I remember. I do and I understand.

Login to post a reply

Server time is: 2024-04-18 10:51:40
Your offset time is: 2024-04-18 10:51:40