Page 1 of 1

Mouse Program

Posted: Fri Nov 23, 2007 4:43 am
by Mr. O
I had some trouble making a working mouse in my programs. It took me about 2 hours just to make this program. So you won't have the frustration I have attached the a mouse program and its code. Hope it helps!
Mr. O

Re: Mouse Program

Posted: Fri Nov 23, 2007 12:49 pm
by Murskaaja
Your system isn't good I'm sorry. Now if I would like the screen to be different size the mouse would show on the wrong place. Or if I wanted to place buttons you could click on it would get very tricky. Luckily there are better ways.

If you need the mouse to deal with objects this would be the way to go:

Code: Select all

ShowMouse OFF
mouseimage = LoadObject("media\mouse.bmp")

Repeat
    // code...

    ObjectOrder mouseimage, 1
    PositionObject mouseimage, MouseWX(),MouseWY()
    DrawScreen
Until EscapeKey()
(objectorder is only needed if new objects are born during the game. And the best place for it would not be in the mainloop as in this example but f.ex in the function that makes those new objects. It's now where it is as I didn't have time to make more detailed examples.)


If you don't need to deal with objects I'd however suggest making the mouse an image instead of an object. That way you don't need to play with objectorder to keep the mouse on top (just place drawing the mouse-image the last thing before drawscreen):

Code: Select all

ShowMouse OFF
mouseimage = LoadImage("media\mouse.bmp")

Repeat
    // code...

    DrawImage mouseimage, MouseX(),MouseY()
    DrawScreen
Until EscapeKey()

PS. For this small examples I'd suggest just copy-pasteing the code here instead of making unnecessary zip packages.

Re: Mouse Program

Posted: Sun Dec 23, 2007 6:18 am
by Mr. O
Thanks for the suggestion of posting the code directly on the forum. You are right that you should use objects only when necessary. The problem is if you use objects you have to make sure you see the mouse. Thanks for the report of the bug. Here is the fixed code.

Best of luck!

Mr. O

The updated code:

Code: Select all

Global mouseimage, mouse_x, mouse_y
SCREEN 1280,800,32,0
mouseimage = LoadObject("bmp\mouse.bmp")
Repeat

    mouse_x = MouseX()
    mouse_y = MouseY()
    PositionObject mouseimage, mouse_x, mouse_y
    ObjectOrder mouseimage,1
    DrawScreen
Until EscapeKey()
P.S. Again thanks for the suggestions and reporting the bugs.

Re: Mouse Program

Posted: Mon Mar 17, 2008 3:55 pm
by Alligaattori
Murskaaja wrote: If you don't need to deal with objects I'd however suggest making the mouse an image instead of an object. That way you don't need to play with objectorder to keep the mouse on top (just place drawing the mouse-image the last thing before drawscreen):

Code: Select all

ShowMouse OFF
mouseimage = LoadImage("media\mouse.bmp")

Repeat
    // code...

    DrawImage mouseimage, MouseX(),MouseY()
    DrawScreen
Until EscapeKey()
You should have a DrawGame before DrawImage because otherwise the image will be drawn under all objects.

Re: Mouse Program

Posted: Tue Mar 18, 2008 4:46 pm
by Mr. O
Thanks for the suggestion. I was not aware of the drawgame keyword. I did not see the keyword in the Engilsh manual. I can't read any other language besides English so I can't have the advantage of reading the Finnish manual. Thanks for the suggestion. I am rewriting the package and posting the edited code.

Again thanks for any suggestions.
Mr. O

Code: Select all

Global mouseimage
SCREEN 800,600,32,0
mouseimage = LoadImage("bmp\mouse.bmp")
Repeat

    DrawGame
    DrawImage mouseimage, MouseWX(), MouseWY()
    DrawScreen
Until EscapeKey()
End