MouseMove Events With Sprites

eww245

Member
Licensed User
As it turns out it is possible to Move Sprites with the Door Library.:sign0060:

I have included a modified SpriteExample that allows this.

In other situations it can be used like this, no Timer is needed unless Sprite.Velocity is used.

B4X:
Sub Globals
     mousedown = false
End Sub

Sub App_Start
     gw.New1("Form1",0,0,Form1.Width,Form1.Height)
           o.New1(False)  'Door Object added after GameWindow created
           o.FromLibrary ("main.gw","_gw",B4PObject(2))
'Door Events
            eMove.New1(o.Value,"MouseMove") 
            eUp.New1(o.Value, "MouseUp")
            ePaint.New1(o.Value,"Paint") 'Start the GameWindow without a Timer
     Sprite.New2(AppPath & "\image.png",1,44,44,1)
gw.Tick 'It Seems to me that using a lot of Ticks, prevents white flashes
     Form1.Show
End Sub

Sub ePaint_newEvent
o.Value = ePaint.Data
     gw.Tick 
End Sub

Sub gw_CollisionMouse    
   mousedown = True 'move only when pressing the Sprite area of the GameWindow
gw.Tick
End Sub

Sub eUp_NewEvent
o.Value = eUp.Data
    mousedown = false 
gw.Tick
End Sub

Sub eMove_NewEvent
o.Value = eMove.Data
    x = o.GetProperty("X")
    y = o.GetProperty("Y")

     If (mousedown) then
Sprite.X = x
Sprite.Y = y
     End If

gw.Tick
End Sub
 

Attachments

  • SpriteMove.zip
    92 KB · Views: 285
Top