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 / 2D Collision With Transparencies

Author
Message
Muriako
15
Years of Service
User Offline
Joined: 11th Aug 2009
Location:
Posted: 31st May 2010 02:58
Alright, so I just started coding again and I want to make a simplistic 2D platformer game, but having never done much with 2D I can't seem to get any decent form of collision going. I've searched around a bit and looked through some code, but I can't seem to find the answer I am looking for.

So right now I have 3 images on the screen, for the character, 'level', and background. To make it easier to deal with, I made the level image the same size as the screen and just left the un-used part transparent. This shows up fine when it is ran, but the character sprite will always detect collision with the level sprite because of that transparency.

Now I'm sure this has been brought up before and solved without too much trouble, but I couldn't find anything that worked for me. I should also mention that I have eXtends, in case that has some command that I somehow missed that would help me here. I looked through all of the documentation and what not for it and couldn't find an answer there either.

Thank you in advance.
Inflictive
15
Years of Service
User Offline
Joined: 16th Jun 2009
Location: Altis
Posted: 31st May 2010 06:23
Hmm... what kind of image is the "level"? If it is BMP, and you are using black as transparent, you may have issues. On the other hand, if it is PNG, and you are using the built-in transparency, you may have some issues too. Whatever it is you are using, I would recommend trying the opposite.

*´¨;
¸.•´¸.•*´¨; ¸.•*¨;
(¸.•´ (¸.Eviljackson1
Muriako
15
Years of Service
User Offline
Joined: 11th Aug 2009
Location:
Posted: 31st May 2010 07:29
I've tried both. I first preferred the PNG route, but once that didn't work I tried BMPs.

I could get the collision working if I wanted to, checking spots around the character sprite and what not, but I figure there should be a more easy and efficient way, and I don't want to be learning to do things a bad way. :p
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 31st May 2010 15:12
Hi, I wrote a basic sprite collision example that uses eXtends commands but the weird thing is that it only works for bmps.

Here it is


You'll have to insert your own media into the example, unfortunately the uploader doesn't like my files so I can't produce the files I used.

Hope this helps

A clever person solves a problem, a wise person avoids it - Albert Einstein
Muriako
15
Years of Service
User Offline
Joined: 11th Aug 2009
Location:
Posted: 31st May 2010 19:54 Edited at: 31st May 2010 20:29
Couldn't get the code to work.

I made replacement images, but it kept giving me "Can't load image" errors. Weird thing is it was saying they were on line 5, even though that's a comment line, and it wouldn't change no matter what I did.

I will try to piece it together by studying your code though, thank you.

EDIT :: Yay, it is detecting now, at least it seems to be. It does seem to stay "detected" once it collides, even if it isn't anymore, but that's likely some trivial error. I have a ways to go before the collision actually means anything, but that's a big step. Thank you for the example code, no idea what I was doing wrong before as it seems to be the same as it was, but it works now!

EDIT :: Well, it seems like it has problems detecting when it isn't colliding anymore. If I set the flag on the SPR Get Collision command to 1, it detects when it hits pretty well, but when I pull the sprite back out it always leaves a random number of pixels still colliding for some reason.

Login to post a reply

Server time is: 2024-09-28 18:16:14
Your offset time is: 2024-09-28 18:16:14