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 to Background Collision Detection

Author
Message
Licaon
20
Years of Service
User Offline
Joined: 30th Sep 2003
Location: Far in the south
Posted: 30th Sep 2003 21:30
Any one has tried to modify the pixel perfect collision code from the forum to allow background collision?
I've tried...complete failure.
Any alternative ideas? anyone has ever rise victorious on this subject?
Waiting for help...

9 of every 10 people are exactly the 90 %
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 30th Sep 2003 21:56
This should be relatively easy, so maybe I'll look at it next week ... I'm trying to get something ready for the convention at the moment
Licaon
20
Years of Service
User Offline
Joined: 30th Sep 2003
Location: Far in the south
Posted: 2nd Oct 2003 23:54
Well, thanks for the reply, hope the convention proyect goes well. Been fooling around with the code, aparently the problem was with a pointer, if the final code is reasonably fast, i'll post it

9 of every 10 people are exactly the 90 %
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 3rd Oct 2003 15:50
What is the pixel perfect collision code and where can I find it?

http://www.freewebs.com/scragglesoft/
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 6th Oct 2003 16:12
Codebase ... where else?
Licaon
20
Years of Service
User Offline
Joined: 30th Sep 2003
Location: Far in the south
Posted: 6th Oct 2003 20:57
I have uploaded a sprite collision to background snipet. it is in the code snipets area. any way, here es again.
it's a simplified pixel perfect sprite to sprite collision that asumes a lot. LOL

Any comments?

9 of every 10 people are exactly the 90 %
Licaon
20
Years of Service
User Offline
Joined: 30th Sep 2003
Location: Far in the south
Posted: 6th Oct 2003 20:58


9 of every 10 people are exactly the 90 %
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 7th Oct 2003 18:47
That's all I would have done too, looks like the fastest perfect 2D collision you can get is through memblocks.


Van-B

My cats breath smells of cat food.
Licaon
20
Years of Service
User Offline
Joined: 30th Sep 2003
Location: Far in the south
Posted: 7th Oct 2003 19:59
Thanks for the feedback Van B
Anyway i think the code could use a little improvment. Like i said, it asumes that the origin coords of the sprite and the background are 0,0. it's a little irritating...

9 of every 10 people are exactly the 90 %
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 10th Oct 2003 16:12
This is a function I have been wanting for a long time.

Unfortunately it is far too slow to be of any practical use. Without it my game can achieve frame rates of around 130 fps but when I use this function it is down to only 5 fps.

I am not criticizing the code because I believe the fault my lay with my own code and the way I have gone about it, so, this post is really a plea for help to optimize my own code.

I am writing a 2D space shooter (think 'Lunar lander' with 2 players and guns) and the way it is written at present is probably not the best way to do it.

I have a 1600 x 1200 screen which has on it a 1600 x 1200 sprite as the background image most of which is empty background space. Would it improve my frame rate if I were to do away with the one big sprite and use tiling instead? And if I did use tiling would I need to check every tile for a collision each game loop?

Thank you
Licaon
20
Years of Service
User Offline
Joined: 30th Sep 2003
Location: Far in the south
Posted: 10th Oct 2003 18:46
I've trying to optimize the code, but not with a substancial increase in frame rate.
To SCRAGGLE:
Tiling is always a good way of treating huges surfaces, anyway, what i'd do in your case is getimage (px,py,px+wi,py+hi) where:
PX: x position of the sprite
py: y position of the sprite
Wi: width of the sprite
hi:height of the sprite

The resulting image,along with the sprite you ar checking, are the parameters for the collision checking...
I dont think it will improve speed, but certainly improves memory usage.
Further more, if i could see the code of your game (at least the graphics loop) i will have more elements to help you.

9 of every 10 people are exactly the 90 %
Licaon
20
Years of Service
User Offline
Joined: 30th Sep 2003
Location: Far in the south
Posted: 10th Oct 2003 18:54
Ups...didnt read well the post:
You are checking colisions between 2 sprites, not a sprite and a image. Unless you have modified the code, i dont see how the snipet helps you, since it asumes the 0,0 coordinates of both the image and the sprite are overlaping (at least locally)
Using a huge sprite as a background, any way, doesnt looks to me as the best solution. I would tile the background, get the image of the colision relevant zone, and only then perform colision checking between the sprite and the background.
That should give a boost to the framerate.

9 of every 10 people are exactly the 90 %

Login to post a reply

Server time is: 2024-05-05 19:18:05
Your offset time is: 2024-05-05 19:18:05