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 DBPro Corner / Simple 2d collision help

Author
Message
Purplepickle
13
Years of Service
User Offline
Joined: 4th Jun 2011
Location: Between hopeless and needs improvement..
Posted: 27th Aug 2011 02:32
Wait!
before you tell me "Did you search the forums?"
read this, I know There is a lot of 2d collision threads but they are not what I'm looking for. I hate to make another thread but I have eXtends and I just want a collision system to keep a sprite from leaving the screen. I can't find anything.
For some reason I can't Get my file and I can't give you my source code because it has media so I'll just explain it. Your a transparent fish (Png, I can't get a bitmap to work) And you swim on a side view of water (Water is a bmp and doesn't move) you move with the arrow keys. I just need literaly a box it has to stay in.
Thank you for all of your help.

Wait, what?
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 27th Aug 2011 03:00 Edited at: 27th Aug 2011 03:13
I could code something up, but it would help to know a few things. btw i don't have extends so I would do something with standard dbpro commands.

Can you either post up the sprite image of the fish? How big is the bounding rectangle of the image, compared to the actual pixels of the fish or explain it's size? Does the fish swim in other directions than just side to side and up and down? Does the sprite rotate? Do you really need near perfect pixel collision detection, or is the bounding rectangle of the sprite image close enough that we can use that. (in other words, the fish may not ever get all the way to the edge of your box, but close enough depending on the sprite border). Are all the animation frames the same size?

honestly posting the sprite image, and explainging the movement or animation frames would greatly help in deciding which route to go.

* The simplest 2d solution is to use bounding rectangle solution. But that may not be good if there is a lot of tranparent area in your sprite frames compared to the actual fish pixels.

* Alternately you could use the center coords of the sprite and then use an offset to the leading edge pixel, and check that agains a min/max x,y of the box.

* another solution could be to have hidden/transparent 3d point and check it agains a hidden/transparent 3d plain. Place the 3d point to update with the center of your sprite every loop, and just check for collison with the hidden box object. the hidden plain object would be smaller than your actual intended box by half the size of the fishes width/height.

*** You could also just check the center of the sprite against a box that is smaller than your intended box. smaller by half the width/height of the sized sprite. This would allow you to just use the center of the sprite, and it would ensure that no part of the fish extends beyond your real intended box.

Once I know what will work for you, and the sprite info I can post some real code to the solutions.

Your signature has been erased by a mod please reduce it to 600 x 120.
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 27th Aug 2011 03:51
Hi there.
@Purplepickle

As I show you in the other post, you can stay in a square (part of the screen) just reffering where you want to limits for x,y

if x<15 then x=15 that means that you can't go out of the screen from left . Take a look to this piece of code.





Cheers.

I'm not a grumpy grandpa
Purplepickle
13
Years of Service
User Offline
Joined: 4th Jun 2011
Location: Between hopeless and needs improvement..
Posted: 27th Aug 2011 04:10 Edited at: 27th Aug 2011 04:17
Alright I got the file through, to answer your questions : it isn't animated, Only arrow keys, it is just a simple png. I don't need anything fancy, I just need somthing like a min x max x coordinate system, I just don't know how to write one. Here is the source code in case the file doesn't work.



I don't know why it won't use the fish as a bitmap (even though in paint it isn't transparent at all) If it makes it any easier as a bitmap I have included the fish as a bitmap. Thanks anything at all is great.

Wait, what?

Attachments

Login to view attachments
Purplepickle
13
Years of Service
User Offline
Joined: 4th Jun 2011
Location: Between hopeless and needs improvement..
Posted: 27th Aug 2011 04:20 Edited at: 27th Aug 2011 04:25
@chafari
Thanks that works.
Thanks I was writing my message at the same time you posted yours so I didn't see it. I made a new thread because I wasn't getting the right type of collision system.
And how would I flip the fish based on direction ( I know it has to do with yrotate)

Wait, what?
chafari
Valued Member
18
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 27th Aug 2011 04:31 Edited at: 27th Aug 2011 04:50
Copy the code in your project and take a look if it works to you.


Edited- haha I'm the same boat, I didn't see your last post. Try last code.




New update for background image




Cheers.

I'm not a grumpy grandpa
Purplepickle
13
Years of Service
User Offline
Joined: 4th Jun 2011
Location: Between hopeless and needs improvement..
Posted: 27th Aug 2011 22:19
Hey I found a sprite collision system in extends that tells you how many pixels two sprites are colliding.

So my game now has three key controlled fish and one mouse controlled worm. The Idea is that each pixel a fish sprite and a worm sprite collide is one point. 1000 points and you win. How would I save the number of pixels a sprite collides with the worm to a total?
I tried somthing like this:


How can I get this to work?
I know I can get the 1000 point win by somthing like this:


Wait, what?

Login to post a reply

Server time is: 2024-11-24 01:28:21
Your offset time is: 2024-11-24 01:28:21