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.

DarkBASIC Professional Discussion / Need help with drag-able window

Author
Message
Beyond the Humans Knowledge
15
Years of Service
User Offline
Joined: 27th Oct 2010
Location:
Posted: 18th Jun 2011 07:14
I am going to make a window drag-able with selections in it for may game, but i dont even know where to start?? Can you help. I know to start with a box of course, but im actually going to use a custom hud.

onhcet d(-_-)b techno
Uncle Sam
20
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 18th Jun 2011 07:54 Edited at: 18th Jun 2011 07:55
You might consider the BBB gui plugin. I haven't used it myself but I hear it is great.

If not that, you could simply store the coordinates for the top-left corner of the window in a variable, and paste the window sprite there. When you want to move it, simply detect if the mouse is over the area of the window where you can drag it from, and then change the window coordinates using mousemovex() and mousemovey().

Beyond the Humans Knowledge
15
Years of Service
User Offline
Joined: 27th Oct 2010
Location:
Posted: 18th Jun 2011 08:09
yeah, thanks for the reply. I had already fixed the problem, but the problem now is that dragging the window is laggy??



Here is my code so you can see for yourself. Dont worry there are no loaded images, just copy and paste.

onhcet d(-_-)b techno
Uncle Sam
20
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 18th Jun 2011 08:22 Edited at: 18th Jun 2011 08:30
No problem.

Ok, there are a few problems here. First, you're embedding a do/loop inside a do/loop in a very odd way. You should never need to do this! The other thing is the code you are using to check whether you are clicking the box:



The "sprite collision" call will return either a 1 or 0 if there is a sprite collision between sprite 1 and any other sprite. You need to check for collision by putting a sprite on the mouse and then checking for collisions with the window sprite.

Maybe I'll try to fix up an example.

EDIT: Ok, here's an example with just the code for moving the window. There is a little jerk when you first click the window (this could be fixed with just a little work), but this shows how it functions.



Beyond the Humans Knowledge
15
Years of Service
User Offline
Joined: 27th Oct 2010
Location:
Posted: 19th Jun 2011 10:25
Ok, now here i have kinda fixed a little of the problem, but still get the lag?? I cant figure out how to make it where whenever you click on the box, you stay on that part of the box instead of shooting onto the top left corner when moving.

Heres the updated code


onhcet d(-_-)b techno
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Jun 2011 11:02 Edited at: 19th Jun 2011 11:04
When I made that code originally I was going to use the mouse but saw that you wanted to use the arrow keys. In the following hold down the mouse button and the box will show up in the grid.

Here's the way I initially intended it to be:


Beyond the Humans Knowledge
15
Years of Service
User Offline
Joined: 27th Oct 2010
Location:
Posted: 19th Jun 2011 11:08
oh, please do post on using the mouse instead of keys. I would want both so i can read the code and learn from it.

onhcet d(-_-)b techno
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Jun 2011 12:08 Edited at: 19th Jun 2011 12:10
The last code snip was the one with the mouse instead of arrow keys. I decided to change it to be like Uncle Sams example that doesn't snap to the grid.

The following uses what is known as a switch (either 0=Off or 1=On) to determine if the box will follow the mouse or not. It checks for a mouse button being hit then checks if the mouse is on the sprite. If it is on the sprite it then checks if the Move switch is off, offsets the sprite relative to the mouse, and realigns the sprite to prevent any "jumping" and turns the Move switch on. Once you let go of the mouse button it'll turn off the Move switch, realign the sprite to prevent "jumping" again, and reset the offset to zeros.

The lag you mentioned was because of the drawing of the grid every loop. I took it out of the DO/LOOP and grabbed an image of the completed grid so this version is lag free.



Beyond the Humans Knowledge
15
Years of Service
User Offline
Joined: 27th Oct 2010
Location:
Posted: 19th Jun 2011 13:04
wow ... your awesome!

onhcet d(-_-)b techno
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 20th Jun 2011 09:44
I kinda just skipped all the comments and read you need draggable windows, and so I made this for you. I tried to comment as much as possible so you can understand what I did.



Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 20th Jun 2011 11:18
Phaelax, that's some cool code you've made there.

Login to post a reply

Server time is: 2026-07-10 21:18:36
Your offset time is: 2026-07-10 21:18:36