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 / Sprite Collision 2d problem

Author
Message
Anthony T
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location:
Posted: 12th Oct 2008 09:17
// Dark GDK - The Game Creators - www.thegamecreators.com

// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application

// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"

// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
dbCreateAnimatedSprite ( 1, "testcursor.png", 1, 1, 1 ) ;
dbCreateAnimatedSprite ( 2, "Create.png", 1, 1, 2 ) ;
// our main loop

while ( LoopGDK ( ) )
{
dbPasteSprite(1, dbMouseX(), dbMouseY());
dbPasteSprite(2,300,300);

if(dbSpriteCollision(1,2) == 1)
{

dbPrint("hey");
}
// update the screen
dbSync ( );
}

// return back to windows
return;
}

It just keeps spamming "HEY" which is wierd. Can anyone please help me, been frustrated for house
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 13th Oct 2008 02:40
Put it in a Code Snippet block and I'll read it.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 13th Oct 2008 06:52
I'm not really sure, but I wouldn't use dbPasteSprite. It doesn't really tell you the sprite position, only that you want the image the sprite refers to to be pasted at that location. Both sprites are probably located at a default location since you haven't actually positioned them.

Use dbSprite () instead, even if it seems to redundantly reassign the image.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
ErDa
16
Years of Service
User Offline
Joined: 17th Feb 2008
Location:
Posted: 14th Oct 2008 05:53
I'm having a similar issue, and from what I've collected, dbSpriteCollision doesn't work and always returns 0.

You could alternatively use something like



That should check if your cursor sprite's top-left pixel is in between the corners of the sprite. The downside is that this is a heck of alot of work if you're going to have many buttons to click or whatever. Also, it only really works of the button-sprite is a square, or else you'll be able to click outside of the edges of the button.

Then there's method 2, which is to draw on the bitmap using dbInk, then checking the color of the mouseX by using dbPoint / dbRGB / dbRGBR / dbRGBG / dbRGBB. But again, that's a heck of a lot of work if you have alot of clickable buttons.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 14th Oct 2008 07:02 Edited at: 14th Oct 2008 07:04
This is why a sprite or button class comes in handy. It's one of the reasons that object oriented programming exists.



This is a small function in my Sprite class. The Sprite class can be inherited to derive a Button class or be used as is.



Admittedly this this should only be done when the mouse is clicked though I have omitted that portion.

The advantage is that you don't have to check each sprite/button's position under the mouse by passing all those parameters to a procedural function.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Mermadak
15
Years of Service
User Offline
Joined: 14th Oct 2008
Location: Chandler, AZ
Posted: 14th Oct 2008 08:36
I am new here so I apologize if this is not the place to post this too, but I am having a similar problem so I thought it would be a good place.

I am trying to do the most basic intro tutorial for the GDK and I am getting two errors I can't get rid of when I build it:

c:\users\parents\documents\visual studio 2008\projects\hellod\hellod\main.cpp(19) : error C2065: '“animatedsprite' : undeclared identifier
c:\users\parents\documents\visual studio 2008\projects\hellod\hellod\main.cpp(19) : error C2228: left of '.png”' must have class/struct/union
type is ''unknown-type''




I have included the code just so you can verify that what I have put in is correct.

Could someone please shed some light on this?

Thank you
Mermadak
15
Years of Service
User Offline
Joined: 14th Oct 2008
Location: Chandler, AZ
Posted: 14th Oct 2008 17:03
Good to know.

I did call dbSprite ( 1, 0, 0, 1 );
in mine, so I guess my problem isn't as similar as I initially thought. Which reminds me...

I did do a bit more troubleshooting and my problem seems to be related to the fact that the image being called is a .png as I built the 2D default program that uses a .bmp and I don't get the errors. The 2D default program doesn't use any additional includes or anything that might make a difference that I can see? Maybe there is some other core application I need to have installed on my system for .png files to work?

So, it sounds like Anthony's should work now. Anyone have any ideas for my issue now?
Anthony T
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location:
Posted: 15th Oct 2008 19:42
well done
Quote: "
"There is no issue. Collision won't work if you don't call dbSprite() to update the sprite's internal data, i.e. its position. dbPasteSprite() only stamps the sprite's image to the screen, that's why collision doesn't work.""


Golden words from a man that drinks golden beer. Cheers WindowsKiller and to all.

Login to post a reply

Server time is: 2024-09-30 09:29:54
Your offset time is: 2024-09-30 09:29:54