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 / Exclude Transparancy?

Author
Message
BeastDeath
13
Years of Service
User Offline
Joined: 7th Jul 2011
Location:
Posted: 31st Oct 2011 17:18
First of all I'd like to thank the community for all the help in my previous posts.

I'm now facing a new problem, is it possible to get the distance of the actual pixels in the image and exclude the transparency? I need the distance to be calculating on the non-transparent pixels.

Attached is an example of what I'm looking for.

Attachments

Login to view attachments
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 31st Oct 2011 19:56
Distance of the pixels...?
Pixels have no distance (they're purely 2d). Do you mean getting the distance to a 3d object (which could of course be a plain, simply having a texture made up of pixels) from ie. the camera?

Excluding transparent pixels in case of a 3d object would probably be quite tedious and something you'd have to implement yourself, but elaborating a bit further on the issue might give you some more direct answers.


"Why do programmers get Halloween and Christmas mixed up?"
BeastDeath
13
Years of Service
User Offline
Joined: 7th Jul 2011
Location:
Posted: 31st Oct 2011 20:40
What I have is the player, I calculate the distance (sqrt formula) of an image that contains transparency, I need the distance between the player and the shown pixels not the hidden transparency.

Also another question, are there any faster ways of collision in 2d/sprite? I use Sprite collision command and external pixel collision (which slows the game extremely) are there any faster pixel collision commands (that can exclude transparency).
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 31st Oct 2011 22:40
Quote: "Also another question, are there any faster ways of collision in 2d/sprite? I use Sprite collision command and external pixel collision (which slows the game extremely) are there any faster pixel collision commands (that can exclude transparency). "


I assume we are talking about a sprite where the actual graphic is not square as is the sprite containing it so therefore the collision will not be perfect.

Can't offer you a way to do it like that. Can offer you a much, MUCH more better way than checking against transparency (which I dunno if DBP supports with sprites anyway). Use 2D pixel-vectoring. It's what I used for collisions in my top-down shooter (which you can find on my site. Be warned, it's age-restricted). You can write one yourself - it's easier than it seems. If you want my source, I'll dig it up and explain the usage more detailed. It's very primitive though but relatively accurate and it's always given me very decent performance.

@Rudolpho: I think he means distance between to points which is valid in 2D. EG P1.x = 30, P2.x = 40, P1.y = 10, P2.y = 10 would mean the distance between the two players is 10 pixels. There's actually a formual for calculating distance based on any number of dimensions. It was in a thread read recently too.

Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 31st Oct 2011 23:00
Ah, I see.
Well, the distance formula is distance = sqrt((x2 - x1)^2 + (y2 - y2)^2)) (for further dimensions one would simply add teir difference raised to the power of two to the value for which to get the square root, ie. ... + (z2 - z1)^2).
Since the square root is relatively slow to compute, it is usually best to have the "target distance" (that is whatever you're comparing the calculated distance to) squared as well, and just skip the root.

Anyway, what you are trying is achieveable (it's pretty much what pixel perfect collision is all about), but it isn't directly easy. At least if you want to be able to rotate or scale your sprites (otherwise you can just read their pixels when registering a square collision).


"Why do programmers get Halloween and Christmas mixed up?"

Login to post a reply

Server time is: 2024-11-22 12:41:58
Your offset time is: 2024-11-22 12:41:58