sprite controlled by mouse
Blitz3D Forums/Blitz3D Programming/sprite controlled by mouse
| ||
I need to move a sprite with the mouse. Screen resolution is variable, so I can not use am absolute formula: [CODE] x#=MouseX() y#=MouseY() xs#=(x/90)-5.5 ys#=(y/90)-5 PositionEntity sp,xs,-ys,0 [/CODE] because at some resolutions it work, and in others, it didnt. How can be done? |
| ||
Something like this might work:Graphics3D 800,600,32,1 Global CAMERA = CreateCamera() Global GH = GraphicsHeight() Global GW = GraphicsWidth() Global HGW = GW * .5 Global HGH = GH * .5 Global MySprite = CreateSprite() : ScaleSprite MySprite, 10, 10 While Not KeyDown(1) Position2d( MySprite , MouseX(), MouseY() ) RenderWorld() Flip Wend ;=========================================================================== ;=========================================================================== ;=========================================================================== Function Position2d( Entity , x#, y# ) Local Offset# = .75 / ( GH / Float( GW ) ) PositionEntity Entity, ( x - HGW ), ( HGH - y ), 400 * Offset End Function |
| ||
You need to derive a formula from the screen-size variable. |
| ||
For some purposes, this might be unsuitable, but you could use a plane and camerapick: |
| ||
[quoe]Screen resolution is variable, so I can not use am absolute formula[/quote] Yet you can make use of the GraphicsWidth() and GraphicsHeight commands, or even CameraViweport |