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 / Mouse click on text

Author
Message
dn5
15
Years of Service
User Offline
Joined: 23rd Dec 2010
Location:
Posted: 23rd Dec 2010 16:32
Hello, what's up guys?

Im new here, so yea, nice to meet you. I've started programming in DarkBasic Pro, since yesterday, quite good language. As I am Delphi programmer for 1 year, I mostly know about programming, variables, if then statements, and much more. I already started somethings but can't make it work.

So I use CENTER TEXT command, to print text on screen, but what Im trying to make is if user click: "free race" it will call function: "NewGame", if user click "settings" it will call function "ShowSett" and so on. I don't have idea how could I know if user click free race or settings.

I think I should use mouse(x) and mouse(y), but I dont have idea how could I done that IN DBPRO, as Delphi is IDE so its simple.

It's something like on this video, that menu at begiging:
http://www.youtube.com/watch?v=NT-oY_ua9vg&feature=player_embedded

Thanks!
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 23rd Dec 2010 17:24 Edited at: 23rd Dec 2010 17:28
Well you just have to check the mouse position with mousex() and mousey() and see if its between the text position and the text position plus it's size.
Here's a little function I wrote to test it.
For the x and y, do the text position minus the width and height divided by 2.
So calling it up would be
OverText=MouseOver("free race",x-(text width("Free race")/2),y-(text height("Free race")/2))



My computer surpasses all the technologies of the day. What computer do I have?

dn5
15
Years of Service
User Offline
Joined: 23rd Dec 2010
Location:
Posted: 24th Dec 2010 13:48
Thanks Madsciencetist for reply, I've try it, but it seems that doesn't work:

(Btw. Sorry If Im wrong, but don't blame me, I'm new to DBPRO.)



Thanks,
dn5
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 24th Dec 2010 16:51 Edited at: 24th Dec 2010 16:53
You have no loop. When the program starts it runs right from the top to the bottom and ends - probably before you have a chance to do anything.

Here's working code (SYNC stuff added to avoid CLS causing a flicker):


dn5
15
Years of Service
User Offline
Joined: 23rd Dec 2010
Location:
Posted: 24th Dec 2010 23:11
O yes, I forgo about main loop. Thanks IanM!
dn5
15
Years of Service
User Offline
Joined: 23rd Dec 2010
Location:
Posted: 25th Dec 2010 15:24
Btw. If someone want's to implement the mouseclick use this function:



I've just added mouseclick() to get result.
Now that I set up everything and works fine, I have some more questions. Sorry, but we are here to help each other

1) Is there any plugin or any paper about loading .BIK files (The classic video files,compressed for games). If so any help would be appriciate.

2) How could I make Typewriter effect in DBPro.
Here Is what I port from my Visual Basic 6 experience to DBPRO:



I think this should work but the only problem is Mid(), Its VB6 command and I dont have idea how could I make it works. The Mid
returns a substring containing a specified number of characters from a string.

strSubstr$ = Mid$("Dark Basic", 3, 4)
Will result to strSubstr this: "ark "

3) Is sync really need to be added to game source. I have my code and type sync on on beggining and sync rate = 40 at the end: sync
And all I see is black screen.
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 25th Dec 2010 22:54 Edited at: 25th Dec 2010 22:56
Some Answers
1) Sounds like a Bink Video File
http://uk.answers.yahoo.com/question/index?qid=20061109012146AA7jIkM

2) Try this - of course change it to suite your needs


3)Yes,
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 26th Dec 2010 01:01
Sync is used to update the screen all at once at a constant rate. It is needed otherwise rendering would be very choppy. The rate makes sure that the screen is updated at a set rate. 60 is often standard.

My computer surpasses all the technologies of the day. What computer do I have?

dn5
15
Years of Service
User Offline
Joined: 23rd Dec 2010
Location:
Posted: 26th Dec 2010 14:36
Thanks, BillR and Madscientist.

BillR:
1) I know what is BIK video file, and what is bink, I used RAD Video tools to compress my intro to BIK. But I don't know how could I load it into DBPRO, because DBPRO allows MPEG, WMV, AVI and MOV files. And no BIK. So I'm asking for some help if there is some plugin to load BIK files to DBPRO games.

2) That example, worked, and thanks for comment, basicly explained everything in one line.

3)For madscinetist also:
So sync will refresh my my screen at specific rate. The problem I did is that I add the sync after "loop" so the sync close before it can update my screen.
But does the sync is necessary in main menu? There isn't anything to render in real-time. Its just text we need to choose.

Thanks once again.
Madscientist
16
Years of Service
User Offline
Joined: 23rd Aug 2009
Location: Between a rock and a hard place
Posted: 26th Dec 2010 23:15
No, only when you need to move things at a certain rate. So you only need cls at the beginning of your loop in your menu. But you will need it in your game loop when you render something such as an object or sprite otherwise they would move at different speeds on different computers.

My computer surpasses all the technologies of the day. What computer do I have?

BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 27th Dec 2010 02:18 Edited at: 27th Dec 2010 02:19
This may be as close as you can get - a commercial encoder for integrating BINK-like video capability into DBPro
http://www.thegamecreators.com/?m=view_product&id=2069
I don't know if they can play a BINK file, but they will encode your other video format to a DarkVideo format giving similar performance as BINK video would.

Otherwise you will have to use another video format native to DBPro.
dn5
15
Years of Service
User Offline
Joined: 23rd Dec 2010
Location:
Posted: 27th Dec 2010 14:29
Thanks BillR, I will try to save money for this Dark Video, so I can buy it.

Madscientits, thank you, I got it.

Now I got another problem. Here is what Im doing: I created menu, and all that in-game menu GUI, but I want to include click sfx, when the button is pressed.
I've manage to do this but the problem is the sound is looping but I need to do sound play only once.

____________
____________| <- One button

If I click on that button sound that I already loaded in memory (Load Sound) will play for example:



Any example with For and Next would be great.
I appriciate your answers.

[Its just me - and my opinion]
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 27th Dec 2010 17:38 Edited at: 28th Dec 2010 23:16
Try this
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 27th Dec 2010 18:17
Because you'll end up have to do this anyway, you might as well set up the mouse for holds and what not. It's incredibly simple, you just need two global variables: mouseClick and _mouseOldClick. Here's an example:



Also it's better to just use the stored mouseclick variable instead of calling mouselclick() multiple time within a loop.

And for the thing your doing:


A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
dn5
15
Years of Service
User Offline
Joined: 23rd Dec 2010
Location:
Posted: 28th Dec 2010 13:32
BillR, I already try declaring like that but It didn't work.

Sasuke: I got it. I could make it to a function, but what's the difference between one up and this you posted?
I see the only difference that with your code I can see you are counting mouse states.

I will soon begin coding the game it self. The main menu is half finished.
Thanks!

[Its just me - and my opinion]
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 28th Dec 2010 17:39 Edited at: 28th Dec 2010 17:39
The first example in my post just shows how you'd find different mouse states using two variables and the counts are just to show it's working.

In the second post I show how to do what you wanted with a sort of one click state. Though, in future, just so you know, button events should only be triggered on mouse release, not mouse click.

I think I understood your post, this line confused me:
Quote: "what's the difference between one up and this you posted?"


A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
dn5
15
Years of Service
User Offline
Joined: 23rd Dec 2010
Location:
Posted: 28th Dec 2010 19:13
O yea, I got it. About that line that I write, You just explained it. I didn't knew what's the difference between the function posted by Madscientist, and You, Sasuke. But I got it, thanks!

Now I'm waiting the answer about sound loop that I ask on post or two before this.

Thanks, dn5

[Its just me - and my opinion]
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 28th Dec 2010 20:13 Edited at: 28th Dec 2010 20:15
Well mine and BillR snippets (though there is a mistake in his snippet, I'm guessing it's just pseudo code, but mouseclick is missing '()' on the end) should work fine. I tested mine a minute ago with some random file, example:



Even tested it with an .ogg file. Still works fine for me.

Also you added this on the end of that post:
Quote: "Any example with For and Next would be great."


What do you need it for?

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
dn5
15
Years of Service
User Offline
Joined: 23rd Dec 2010
Location:
Posted: 29th Dec 2010 13:43
Sasuke, I got it. Works fine for me also.

And never minda bout For and Next because I had to make something loop for specific times. But I got it.
Thanks for time you've spent to answer on my questions.

[Its just me - and my opinion]

Login to post a reply

Server time is: 2026-07-18 07:31:18
Your offset time is: 2026-07-18 07:31:18