sprite controlled by mouse

Blitz3D Forums/Blitz3D Programming/sprite controlled by mouse

Dimas(Posted 2010) [#1]
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?


Stevie G(Posted 2010) [#2]
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




AJ00200(Posted 2010) [#3]
You need to derive a formula from the screen-size variable.


Warner(Posted 2010) [#4]
For some purposes, this might be unsuitable, but you could use a plane and camerapick:



_PJ_(Posted 2010) [#5]
[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