Page 1 of 1

Sloppy, non transparent mouse

Posted: Tue Feb 21, 2006 10:31 pm
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

Posted: Tue Feb 21, 2006 10:38 pm
by Comtois
i dont see UseJPEGImageDecoder() in your code

Try DisplayTransparentSprite() for the mouse
And have a look at TransparentSpriteColor(#Sprite, Red, Green, Blue)

Posted: Tue Feb 21, 2006 10:44 pm
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 :)

Posted: Tue Feb 21, 2006 11:56 pm
by Fred
you can try with MouseDeltaX/Y(), you could adjust the mouse speed then.

Posted: Wed Feb 22, 2006 12:13 am
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?

Posted: Wed Feb 22, 2006 12:22 am
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.

Posted: Wed Feb 22, 2006 12:42 am
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 :)

Posted: Mon Feb 27, 2006 1:07 am
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.