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 / Question Regarding Using Sprite For A Mouse Cursor

Author
Message
ABXG
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Canada
Posted: 1st Apr 2009 20:11
* I have only been using DarkGDK for ~3 days and only been using C++ for ~4 months as part of my university education ( am not in for a computer related major/minor). That being said I am a quick learner and am enjoying working with computer programming.


I am looking to use a sprite as a mouse cursor in my game. I figured out a piece of code that could take my .png or .tga file and display it at the cursor posiion:



This worked, sort off. The problem I am having is that there is a noticeable time delay between the player moving his mouse and the sprite cursor being displayed at the new position on the screen. This is especially noticeable when the player is moving the mouse rapidly.

I tried the dbChangeMouse(#); command but I can't get it to display anything besides the standard Windows mouse/hour glass.

I was wondering if anyone could give me a detailed solution of how I can implement a proper custom cursor without it lagging behind the true position of the mouse.

Thank you for any input.

Thanks
Sharp Bullet
16
Years of Service
User Offline
Joined: 5th Feb 2008
Location: Pluto
Posted: 1st Apr 2009 21:21
You can simply use:

dbPasteImage( int imgID, float posX, float posY )

to don't get any lag.

First say to yourself what you would be; and then do what you have to do.
ABXG
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Canada
Posted: 1st Apr 2009 21:41
Using:

dbPasteImage(200, dbMouseX(), dbMouseY());

still results in a very noticeable lag in position between where the mouse actually is and where the sprite is drawn.
ABXG
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Canada
Posted: 1st Apr 2009 21:44 Edited at: 1st Apr 2009 22:52
*** EDIT *** Double post, sorry
Sharp Bullet
16
Years of Service
User Offline
Joined: 5th Feb 2008
Location: Pluto
Posted: 2nd Apr 2009 12:34
if you want to make a menu try (before showing any image (or sprite) from the menu (and the mouse...)) to make a new camera far away from default camera and set that to default with

dbSetCurrentCamera( int camID )

and when you exit just delete the camera and re-enable the last used camera.

First say to yourself what you would be; and then do what you have to do.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 3rd Apr 2009 01:04
Why are you using dbOffsetSprite()? Why not just use dbSprite(dbMouseX(), dbMouseY(), imgnum) ?

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
ABXG
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Canada
Posted: 3rd Apr 2009 03:06
I tried that and am still getting significant mouse lag.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 3rd Apr 2009 03:22
Quote: "I tried that and am still getting significant mouse lag."


Maybe you'd better define "lag". I'm doing pretty much that and it doesn't present any problem.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
ABXG
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Canada
Posted: 3rd Apr 2009 04:16
By lag I mean that that there is delay between me moving my mouse and the sprite I am using being updated to the new position of my mouse.

For example, if I move my cursor quickly across the screen from the left side to the right side the sprite will drawn to the left of my current mouse position, how far depends on how quickly I move my mouse.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 3rd Apr 2009 04:36
Quote: "For example, if I move my cursor quickly across the screen from the left side to the right side the sprite will drawn to the left of my current mouse position, how far depends on how quickly I move my mouse.
"


And then it catches up? What you expect it to do would work if you could move your cursor across the screen in less than an 60th of a second (or whatever your refresh rate is) AND you could start the move immediately after the mouse was last polled. In other words, if you could spontaneously move the cursor from one side of the screen to the other.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
ABXG
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Canada
Posted: 3rd Apr 2009 05:22
If I understood your response correctly, yes. I am looking for some way to keep the mouse sprite perfectly in sync with the actual location of my mouse.

The way I am planning combat in the game I am working on will require fairly fast mouse movement to function properly so having a lagging cursor sprite would hamper he combat in my game.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 3rd Apr 2009 05:36
Quote: "The way I am planning combat in the game I am working on will require fairly fast mouse movement to function properly so having a lagging cursor sprite would hamper he combat in my game."


I think you're being unrealistic. If you poll the mouse and use its position before you get to your end point (in mid move) you're going to get your sprite displayed wherever the mouse is at the time it's polled. Within the next frame you may get caught up.

Maybe you can think of something clever that will second guess where you want to stop the mouse or delay the poling until the mouse is where you want it but if you could you might be affecting the behavior of other factors in the game.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Warspawn
19
Years of Service
User Offline
Joined: 6th Apr 2005
Location: Arizona
Posted: 3rd Apr 2009 22:42 Edited at: 3rd Apr 2009 22:43
adding the mouse move to it will help, still not perfect, but will help.



there is probably some kind of smoothing math that can be done, but I dont know what it is.

-Warspawn
Grandma
18
Years of Service
User Offline
Joined: 26th Dec 2005
Location: Norway, Guiding the New World Order
Posted: 30th May 2009 12:10 Edited at: 30th May 2009 12:12
That's strange. In DBP the sprite command will put the image pretty much right on the cursor, but in GDK, it's lagging somewhat behind. Using the same commands (or GDK equalents).

*edit sorry for bump, didn't see the old date. I'd like to know why it's acting this way in GDK however.

This message was brought to you by Grandma industries.

Making yesterdays games, today!
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 31st May 2009 01:42
Use the LoadCursor windows api function, and then SetCursor to set it. http://msdn.microsoft.com/en-us/library/ms648391(VS.85).aspx explains its usage.

You can only do the standard 4 colour cursors with that though (black, white, transparent, inverted).

WH8
15
Years of Service
User Offline
Joined: 17th Mar 2009
Location:
Posted: 2nd Jun 2009 04:25 Edited at: 2nd Jun 2009 04:41
Did you see the solution in a thread that I created? The following is a link to the thread. The solution is near the bottom. Perhaps it is in the second last post?

http://forum.thegamecreators.com/?m=forum_view&t=149672&b=22

You can't just use LoadCursor(), or LoadImage(), etc and then use SetCursor(). It doesn't work because there is a code created by the Dark GDK creators that will change the cursor back to the default cursor every time the mouse is moved. One way to solve the problem is by changing the default cursor to your custom cursor. This default cursor is called the active cursor by the Dark GDK creators. How to change what cursor is the active cursor is posted by SmK in the thread that I created. The link to the thread is above. He talks near the bottom of the thread.

Login to post a reply

Server time is: 2024-11-05 23:24:58
Your offset time is: 2024-11-05 23:24:58