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 / Mouse over simple code issues.

Years of Service
User Offline
Joined: 22nd Nov 2012
Posted: 22nd Nov 2012 19:10
SO I'm pretty new to programming. I'm taking a class right now that uses DarkGDK with visual C++.

Right now I'm trying to write a mouse over program for an assignment. It should be fairly easy but for some reason I can only get it to partially work.

The program is suppose to display an image and if you mouse over the image, it swaps to a second image. then if you move the mouse away it suppose to swap back.

Well I can only get it to swap from the first image to the second. After that it wont do anything.

I'm required to code up a value returning function, which is the bool mouseOver(). This is what I'm using to determine if the mouse is over the image. If its true, change it, if its false, paste the first image.
i feel like the problem has something to do with this, the mouseOver() fuction is staying true.

Any advice is appreciated!! Thanks!

//Chapter 9 program

#include "DarkGDK.h"

void loadImages();
bool mouseOver();

void DarkGDK(){

if(mouseOver() == true)
dbSprite(2, 200, 200, 2);
dbSprite(1, 200, 200, 1);


bool mouseOver(){
int mx = dbMouseX();
int my = dbMouseY();

if(mx >= 200 && mx <= 250 && my >= 200 && my <= 270)
return true;

void loadImages(){
dbLoadImage("Joker_Black.bmp", 1);
dbLoadImage("Joker_Red.bmp", 2);
AGK Developer
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 23rd Nov 2012 14:14 Edited at: 23rd Nov 2012 14:17

First of all, try to use code tags the next time, it will make your post much more readable

There is no "return false" statement in your "mouseOver()" function at all, so it can never return the appropriate value if the mouse is not over the image! Also a function that returns a value should always have a default return value just in case no other condition is set. So just change your function to this:

Also you should check your "if"-conditions in this function. If your image size is 50 x 70 then your bottom right corner pixel is 249, 269 because the pixels start to count at 0, 0. So you should change your if statement to one of these to be precise:

And additionaly I think you should think about how you handle your sprites. If I remember correctly (haven't worked with DarkGDK in a while) the command "dbSprite()" always creates a new sprite, so just use this once before your loop (creating one sprite, one ID) and just use "dbChangeSprite()" or something similar to change the image that your single sprite uses. This will be more effective and save memory.

Hope this helps! (I typed this up in a hurry so excuse me for any stupid mistakes...)

Login to post a reply

Server time is: 2024-03-01 07:41:36
Your offset time is: 2024-03-01 07:41:36