Sprite as a mouse pointer

Blitz3D Forums/Blitz3D Beginners Area/Sprite as a mouse pointer

DheDarkhCustard(Posted 2009) [#1]
Simple. How do I use a 3D sprite as a mouse pointer?

Eg. draw a sprite at the proper MouseX() MouseY() of the mouse?


xtremegamr(Posted 2009) [#2]
The best way to do it is to use a DLL (like Sprite Candy).

If you can't be bothered, just draw the mouse pointer as a 2D image, like this:

Graphics 1024,768,0,2

mouseimage=LoadImage("mouseimage.jpg")

While Not KeyHit(1)

SetBuffer BackBuffer()
Cls

;render stuff to the screen

UpdateWorld
RenderWorld

DrawImage mouseimage,1024/2,768/2

Flip
Wend
End


The only problem with not using a DLL is that Blitz doesn't mix 2D and 3D very well, so this will slow down your program.


AJ00200(Posted 2009) [#3]
You could position it a little was in front of your camera and then parent it to the camera, and then move it MouseXSpeed * multiplierValeConst


Kryzon(Posted 2009) [#4]
Hello DheDarkhCustard,

try this: http://blitzbasic.com/codearcs/codearcs.php?code=321

Thank god for the Code Archives!


xtremegamr(Posted 2009) [#5]
But if you use a sprite, won't it be able to clip through the game world?


Kryzon(Posted 2009) [#6]
It sure will, especially if you don't use the handy EntityOrder.

EntityOrder Cursor,-999 

...and there you have it.


GIB3D(Posted 2009) [#7]
Btw, SpriteCandy is not a DLL, it's an include.


DheDarkhCustard(Posted 2009) [#8]
Thanks for the replies guys!

The slowing down while mixing 2d and 3d is the very reason I think it is better to stay with all 3d with this, also using a sprite looks a lot better when using transparency (no pixelated edges)

I have used entityorder before but have found that using it with a lot of objects slows down the program quite a bit, but i'm guessing just 1 sprite should be fine.

I have positioned the pointer a little further back from the camera and put it to the front, but the hard part is getting it to be at the same position as the mouse x and y, is there a special formula to use to do this?

Kryzon, your link looks pretty promising but will it work in a 3d world properly? i havnt fully tested it yet but while the camera is zoomed and with that range it looks like it might make everything look flat? If so this might be good for making 2d games with 3d sprites am i right?


Kryzon(Posted 2009) [#9]
Hello Custard,

you can be sure that that code is specifically for 3D worlds, as it doesn't use any of the image commands.

The purpose of that code is to position a sprite using 2D coordinates, just like you would do it with an image.

Use MouseX() and MouseY(), and the sprite will be positioned at the mouse coordinates just like that. Make sure to take into consideration that sprites are handled by their center, so if you want a cursor to have it's tip at the mX() and mY(), it's texture should be a little offsetted so the tip lies in the center of the texture. Try it out and you'll see what I mean.

Also, make sure to use EntityOrder so it won't be occluded by other visual entities (I'm sure it shouldn't slow down your program, all it does is set the rendering order and disable the object's Z-Buffer).

Good luck.