Mouse Program

Do you have something to share with us? A tip for newbies, perhaps? Post it here.
Post Reply
Mr. O
Newcomer
Posts: 32
Joined: Thu Nov 15, 2007 4:10 am
Location: United States

Mouse Program

Post 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
Last edited by Mr. O on Tue Mar 18, 2008 4:48 pm, edited 1 time in total.
Murskaaja
Member
Posts: 92
Joined: Tue Aug 28, 2007 8:19 pm
Contact:

Re: Mouse Program

Post 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.
ASCII star wars Xtreme | Cool Bombers | Combat (kehitteillä)

RedShadow productions
Mr. O
Newcomer
Posts: 32
Joined: Thu Nov 15, 2007 4:10 am
Location: United States

Re: Mouse Program

Post 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.
Alligaattori
Active Member
Posts: 135
Joined: Fri Mar 07, 2008 8:49 pm

Re: Mouse Program

Post 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.
Mr. O
Newcomer
Posts: 32
Joined: Thu Nov 15, 2007 4:10 am
Location: United States

Re: Mouse Program

Post 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
Attachments
mouse.zip
(587.49 KiB) Downloaded 627 times
Post Reply