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 / Collision Detection Off Center

Author
Message
treeman
14
Years of Service
User Offline
Joined: 15th Sep 2010
Location: My Cave
Posted: 18th Sep 2010 07:58
I am currently working on a game that uses sprites for graphics. I have tile based levels and loading working and am now working on collision detection. The collision detection appears to work but is off center, I have tried to fix it but I just cant work out what is causing it. Can someone please have a look at my code and try to figure out what is wrong?

I have attached my project files in a rar, the collision is in the subroutine "Coll". Hopefully my code is readable enough.

Attachments

Login to view attachments
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 18th Sep 2010 21:04
I can't look at your code right now, but have you tried offsetting the sprites?

Computers do exactly what you tell them.........don't you hate that sometimes?
treeman
14
Years of Service
User Offline
Joined: 15th Sep 2010
Location: My Cave
Posted: 19th Sep 2010 02:38
I managed to fix it, the collision seems to be offset by the size of the sprite, I still have no idea why though so if anyone still wants to look through my code and find out that would be cool .

Also, wheres the winky face emoticon? .
treeman
14
Years of Service
User Offline
Joined: 15th Sep 2010
Location: My Cave
Posted: 19th Sep 2010 02:46
Sorry for double posting but my account is still in the newbie stage (I dont know what to call it :\).

I fixed the problem, I had assumed that when sprites were drawn they were drawn so that the center was at the coordinates given (I have no idea why I assumed this as it is not the standard way). I made the top left collision point to be player position + 0 and it works. Such a silly mistake for all the time I spent trying to fix it .
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 20th Sep 2010 18:49 Edited at: 20th Sep 2010 18:52
Quote: "Sorry for double posting but my account is still in the newbie stage (I dont know what to call it :\)."


It's a "Newbie Slap".

Normally the upper left of the sprite is where the sprite is placed but if you used OFFSET SPRITE... whatever the offset you assign to the sprite is the new center. If you intend to use ROTATE SPRITE you should offset the sprite to it's center so it rotates around it's center.



The above code snip creates a box and rotates the sprite. When you want to center the sprite with OFFSET SPRITE hold down the spacebar and let go of the spacebar to return to the normal offset. Normally you only want to use OFFSET SPRITE once and not constantly like this does... I mean the offsetting back to 0,0 when not hitting the spacebar... it's just a quick example.

Login to post a reply

Server time is: 2024-09-28 22:27:30
Your offset time is: 2024-09-28 22:27:30