Sloppy, non transparent mouse

Advanced game related topics
Roger
User
User
Posts: 33
Joined: Thu Feb 16, 2006 1:53 pm

Sloppy, non transparent mouse

Post by Roger »

I decided to start with some game programming lately, and I quite manage to create a screen, and render images on it etc. but I noticed I had to create a mouse icon myself.

I created a nice sword, using Adobe photoshop elements with a transparent background, but no matter what extension I save it in, it always has a black or white background in my program. Furthermore the mouse is quite slow, so I'll post my 'mouse' code as well...

Code: Select all

LoadSprite(#mouseSprite,"media\images\mouse_cursor.jpg",0)
InitMouse()

Repeat

  FlipBuffers()    

  ClearScreen(0,0,0)

  ExamineMouse()
  
  MX = MouseX()
  MY = MouseY()

  DisplaySprite(#mouseSprite,MX,MY) 

Until QuitGame = 1
As you can clearly see, it's not all code, but it's all my code that concerns the mouse. I place my mouse on the screen after all other drawing. I really don't know how to make the square in which I made my mouse icon transparent, and the mouse is still quite slow. I hope to find some suggestions here :P
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

i dont see UseJPEGImageDecoder() in your code

Try DisplayTransparentSprite() for the mouse
And have a look at TransparentSpriteColor(#Sprite, Red, Green, Blue)
Please correct my english
http://purebasic.developpez.com/
Roger
User
User
Posts: 33
Joined: Thu Feb 16, 2006 1:53 pm

Post by Roger »

Thank you very much for your suggestion. I now have a transparent mouse, but it's still a bit slow. I suppose that's just normal if you load more and more images on a screen.
And I did use the decoder for JPEG, only I didn't include it in my code example :)
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

you can try with MouseDeltaX/Y(), you could adjust the mouse speed then.
Roger
User
User
Posts: 33
Joined: Thu Feb 16, 2006 1:53 pm

Post by Roger »

But MouseDeltaX/Y() only returns a value, doesn't it? How would that increase my mouse speed? And I'm not sure about this, but can it be that my "apparent" mousespeed can be slow because of the time the mainloop takes?
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Basically, it's a delta, so you just have to store the old value and add the delta:

Code: Select all

#Speed = 2
MX + MouseDeltaX()*#Speed
If MX < 0 : MX = 0 : Endif
If MX >= ScreenWidth : MX = ScreenWidth-1
and the same for MY.
Roger
User
User
Posts: 33
Joined: Thu Feb 16, 2006 1:53 pm

Post by Roger »

Ah, thanks a lot, it works like a charm. I had to mess around a bit to get it working but now it does and I can happily adjust mousespeed now. I think I got a bit fixed on the idea that the mouseposition was like a 'fixed' position, only attainable by MouseX/Y(). However, if you set your own variable for the mouseposition there's no reason why it shouldn't work, as long as everything else in your code uses that var :)
MadMax
Enthusiast
Enthusiast
Posts: 237
Joined: Mon Oct 06, 2003 11:56 am

Post by MadMax »

Even if you use mouseX() and mouseY() the code should be fast, at least until PB 3.94 havent tried the beta yet.
Post Reply