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 / Strange error, dbSpriteHit or dodgy c++ skills. Help needed

Author
Message
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 10th Sep 2010 15:47
Hi,

I've been a reader of this forum for a long time but never bothered to create a forum profile, I was happy stalking you guys.
Until now, when I have a problem I need help with.

The thing is, a year ago or so I started coding a "chipdisk". It's a remnant from the old demoscene in 80's/90's. It's a basically a music player that is supposed to play some .mod files from my old "group" and look ok while it plays, maybe with some info and so on.

I'm using VS Express 2008 with Dark GDK.

Enough background, the problem is it's stopped working from where I left it a year ago. At first it wouldn't compile at all but I sorted that out, it was the old atls.lib stuff messing about an' that.

It compiled and looked like it should, but! I can't click any of the buttons in the player, it's like the dbSpriteHit just doesn't register, or my variables are being reset immediately. I just can't see any problems in the code.

It's in beginner stages so it's not very long yet, I'll just post the entire code here shall I?

If you need the whole project (just a few pics for now) I'll put code and pics in a rar and attach it.

Thanks for any comments and/or help!


My hovercraft is full of eels
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 11th Sep 2010 13:03
Use dbSpriteCollision instead of dbSpriteHit. There is a big difference in how they work. dbSpriteCollision returns a hit continuously as long as the two sprites overlap. dbSpriteHit returns a hit ONCE and then not again until the two sprites move away from each other and then overlap again.

Since you hover the mouse inside the sprite for a while (even if only for a split second) before clicking the sprite, the first hit is registered when you set the value of spriteHovered (once, but it is reset immediately in the next loop) and the dbSpriteHit calls inside the dbMouseClick condition will never return anything. So my advice is to exchange those calls for dbSpriteCollision.

I have another advice for you. It is not efficient at all to call data-returning functions several times in one loop, for two reasons. First because all function calls cost time and power for the CPU (and a function like dbSpriteCollision takes a whole lot of time to complete). Second because with a repeated function call, you can even receive a different result, when you really want to work with the same data throughout one loop (one screen refresh cycle). Take for example your mouse() function which calls dbSpriteHit no less than three times when one call would be quite enough to set the values of all three variables. It also calls dbMouseX and dbMouseY two times. A quick example how this function could be improved (I already exchanged dbSpriteHit for dbSpriteCollision):



Further, in the MouseAction function, you call dbSpriteHit again, I don't really understand why, since spriteHovered is already set so you can just check its value.

In the debug function, I guess the only reason for introducing more variables is that dbPrint would not compile with an integer? That could have been solved with a simple typecast:



But the best thing to do would be to use sprintf to format your output strings and then you won't have such problem:

lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 11th Sep 2010 13:36
Excellent.

Thank you for all your fine advice, and the difference between dbSpriteHit and dbSpriteCollision is duly noted.

I've never considered the extra processing time calling such functions many times in a cycle would cause, but it's also true that I do want to work with the same data in that cycle. So thanks for that.

The strange thing is that this code worked perfectly with clicking and everything before, and just stopped working without me working on it for years.

Very good, I'm going to try out your superb advice as soon as I have time!

Thanks

My hovercraft is full of eels
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 12th Sep 2010 14:19
I don't know why the code worked before and not now, but since Dark GDK had several updates in the past years, it's even possible that its behaviour has changed. Maybe you have a newer version installed now?

I didn't actually test my suggested solution since it's a bit difficult to test a srite-based program without the sprites, but if it still doesn't want to work then post again and I'll have another look at it.
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 13th Sep 2010 15:27
It's true I might have a newer version now.

I haven't had time to mess with it yet but I will certainly ask again if I can't get it to work

My hovercraft is full of eels

Login to post a reply

Server time is: 2024-07-02 08:51:59
Your offset time is: 2024-07-02 08:51:59