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 / help with an OOP Dice Simulator

Author
Message
MelliMelz
14
Years of Service
User Offline
Joined: 24th Apr 2010
Location:
Posted: 25th Apr 2010 05:20
I'm taking a C++ class and we're using the DarkGDK library for codes and the Tony Gaddis book: Games & Graphics in C++. In Ch 12 there is a programming Exercise called Dice Simulator where I have to create a Die class that can simulate the rolling of a dice when the space bar is pressed (I wrote an animation for this). I'm having a hard time with this object-oriented programming (and programming in general) but I came up with something using sprites. The only problem is that when I press the space bar to start the dice animation it doesn't do it on both dices at the same time but it runs the animation on one dice then once it's done it runs the animation on the second dice. Could anyone help me with this? By the way this is my first programming class ever and I'm not very familiar with everything the DarkGDK library offers or what I can do with C++ aaand this is my first time using the forums.
Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 25th Apr 2010 11:31
Its the way your playSprite() function is set up, it has a loop which wont let the function return until it is finished.
I would probably have an update() function and then a STATE variable which would maybe be 1 if playing and 0 otherwise.

Then in your update() function check whether STATE == 1, if so, then call playSprite(), playSprite() would then need to be changed so it does not loop through all images but just increments by 1 and then maybe checks whether its finished or not.
In your main loop, only update() is ever called and then the die should do the correct thing depending on its state.

It probably needs a bit more thought than I have put into it but I hope this helps.

fire ball
14
Years of Service
User Offline
Joined: 15th Jan 2010
Location: indonesia
Posted: 25th Apr 2010 20:54
don't use looping..
Interplanetary Funk
14
Years of Service
User Offline
Joined: 19th Apr 2010
Location: Ipswich, United Kingdom
Posted: 26th Apr 2010 01:31
instead of looping through the images use dbCreateAnimatedSprite() and dbPlaySprite().

you can find these quite easily in the documentation under sprites.

Login to post a reply

Server time is: 2024-11-20 01:20:50
Your offset time is: 2024-11-20 01:20:50