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.

Dark GDK / 2d Collision

Author
Message
Brandon Heat
15
Years of Service
User Offline
Joined: 28th Nov 2008
Location:
Posted: 9th Dec 2008 09:33
Hi everyone, I'm working on a 2d game using tiles, and was wondering what the best way is to deal with collision and checking what tile the player is on top of.

I've heard of Sparky's driver but when reading about it it seemed to deal with 3d more so than 2d.

I was hoping for something like this

get player x and y

if (player x and y are on tiles 1, 2 or 3)

player is safe and on the ground

else

player is dead/ misjump

Thanks for your help!
CheatCat
17
Years of Service
User Offline
Joined: 7th Mar 2007
Location: Sweden
Posted: 9th Dec 2008 13:39
Well, you can use:

Or something.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 9th Dec 2008 15:09
dbSpriteCollision(playernr,0)
im pretty sure this doesnt work when set to zero to return any sprite number its colliding with, im not 100% sure but seem to remember it doesnt work the way it should.
The 3D version of that command works dbObjectCollision(playernr,0) but that also has its own problems thats why peolple use sparkys.

if you are going to use dbSpriteCollision(), you may have to check each tile individually.
if ((dbSpriteCollision(playernr,1))
||
(dbSpriteCollision(playernr,2)))
But im sure theres a better way using a matrix or something but ive never done it.
CheatCat
17
Years of Service
User Offline
Joined: 7th Mar 2007
Location: Sweden
Posted: 9th Dec 2008 15:43 Edited at: 9th Dec 2008 15:44
Quote: "If a target sprite has not been specified and a value of zero has been used, this command will return the sprite number of any sprite overlapping it."

Well, it will work...
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 9th Dec 2008 16:32
"Well, it will work... "

You'd think so wouldnt you, try it.
CheatCat
17
Years of Service
User Offline
Joined: 7th Mar 2007
Location: Sweden
Posted: 10th Dec 2008 15:42 Edited at: 10th Dec 2008 15:43
I have tested and it works. dbSpriteCollision(s, 0) returns the sprite that sprite s collide with.
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 10th Dec 2008 17:22
"I have tested and it works. dbSpriteCollision(s, 0) returns the sprite that sprite s collide with."

Good to know, maybe its been fixed, or maybe I was doing something wrong (wouldn't be the first time).
Brandon Heat
15
Years of Service
User Offline
Joined: 28th Nov 2008
Location:
Posted: 11th Dec 2008 04:44
Thank you all very much for your replies.

Interesting would that mean that dbPasteImage when setting up the screen would have to be dbSprite?

At the moment i'm using dbPasteImage to make the level i would imagine that dbSpriteCollision would not be able to handel an sprite and a image would this be correct?

Also when i try and use dbSprite or dbPasteSprite the level is not built.

So i'm alittle bit confused about what to do and how i would make a level out of sprites.
CheatCat
17
Years of Service
User Offline
Joined: 7th Mar 2007
Location: Sweden
Posted: 11th Dec 2008 10:58
If you what to check if you collide with a image, you must do an own collision function. It is easy to do a such function if you want to use block collision.

Are you sure that you load the image before you sprite it?
Brandon Heat
15
Years of Service
User Offline
Joined: 28th Nov 2008
Location:
Posted: 11th Dec 2008 22:21
I see, could you please give me a very small example of a block collision?

Many thanks i searched for it and it cam up with nothing. Thanks
Luciant
15
Years of Service
User Offline
Joined: 11th Dec 2008
Location:
Posted: 12th Dec 2008 02:11
I am having the same issue.

I am using Mappys tile creator and i am exporting a .bmp file. In code i loop through all frames in that image and paints them into a grid. 10x10.

I use the .txt export to get the array on what u can collide with and what you cannot.

The issue I have is converting the sprites position which is smooth movement, into a detection function that determines what tile it is in. I was doing a sprite position / 32 (tile size) but the collision detection function is off by half a tile.

everything is matching up in the array and the graphic but there is an issue with the coordinates i am using.

so how would a sprites posistion be convered into a whole number to which tile it is in so i can check it in the 2D array

if array[xpos][ypos] == 1
then load last position of x and y.


it works but im off half a tile.. and changing the values by .5 would make the array crash since its wnats integers for the indexes.
Brandon Heat
15
Years of Service
User Offline
Joined: 28th Nov 2008
Location:
Posted: 12th Dec 2008 13:06 Edited at: 12th Dec 2008 13:26
Your way of doing it is excellent for me and i can use it to solve my problem!

What your doing should work i think.

if you wanted to get the x and the y as ints instead of doubles i would just cast them



At least i think that will work.

Yeah i tested it in my game and works fine, at least it appears that way! Thanks you solved my problem lol hope all goes well!

Login to post a reply

Server time is: 2024-09-30 13:34:18
Your offset time is: 2024-09-30 13:34:18