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 / Print score

Author
Message
Linuus
13
Years of Service
User Offline
Joined: 16th Jul 2010
Location:
Posted: 29th Jul 2010 22:41
So I've made a little 2d game... The goal is to stay on the screen for as long as possible and everything runs fine, but now when I want to show the player his score I can't figure out what to do.
I want it to be like this:

while(LoopGDK())
{
score += 1;
//now I need a way too delete old text
//The print a new one with the text "score: " followed by the variable score

//rest of loop
}

I've tried dbPrint and dbText but I can't get them to show up (maybe because of background sprite?) and even if they did show up I don't know how to include a variable or delete the text again before it's printed again.

Any help?
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 30th Jul 2010 00:35 Edited at: 30th Jul 2010 00:38


oh on a side note, you are increasing the score once every loop, if you have 60 FPS, then you are increasing score by 60 every second, the number would be increasing very fast and it would look retarded not to mention that your FPS may get up to 1k-2k, you better make a timer and increase it by an ammount after some time

Unseen Machine
13
Years of Service
User Offline
Joined: 23rd Jul 2010
Location:
Posted: 30th Jul 2010 01:08
I have the same problem, i tried

dbText(x,y, dbStr$(scoreval));

And it dont work. Does not recoginize dbStr$ (even though i got it from the help file!!) Do i need to #include somthing else to get that working?
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 31st Jul 2010 11:07
There is no dollar sign after dbStr. (Part of the help was copied from Dark Basic Pro, that's why it has sometimes unnecessary dollar signs.)

But in any case, do not use dbStr like this because it will cause a memory leak. Dark GDK functions that return strings create a new string every time they are called. You should store the returned string pointer and then delete[] it after use, which is uncomfortable. You are much better off with sprintf or sprintf_s, as recommended above by Hassan. That also gives you the possibility to include the number into a string, e.g. "The score is: %d", which would require even further hassle with dbStr.
Unseen Machine
13
Years of Service
User Offline
Joined: 23rd Jul 2010
Location:
Posted: 31st Jul 2010 16:43
So i begin to find the real differances between C++ and BASIC!!

I've not seen the sprintf command before, i'll look into it. Thanks for the help.
Linuus
13
Years of Service
User Offline
Joined: 16th Jul 2010
Location:
Posted: 31st Jul 2010 19:33
Thanks I got it to work but it's still drawn behind the backdrop sprite, how can I draw the text over the background?
Serial Velocity
15
Years of Service
User Offline
Joined: 24th Aug 2008
Location:
Posted: 1st Aug 2010 15:57
Try using dbDrawSpritesFirst before the main loop.

GDKUtilities, a utility library for DarkGDK, avaliable here

Login to post a reply

Server time is: 2024-07-02 09:32:11
Your offset time is: 2024-07-02 09:32:11