Touch event in Gameview

Vabzboy

Member
Licensed User
Longtime User
In the animation "Catch the Bouncing Smiley" where upon touching the ball, the ball changes direction.

In Gameview, How would i implement this through the Touch event. It is working allright but when I touch the ball on its center or on its face nothing happens.

Anyway.. Can you guys help me out with what code should be correct for doing this.
 

Vabzboy

Member
Licensed User
Longtime User
In the Catch the Bouncing Smiley:

B4X:
Sub Activity_Touch(Action As Int, tx As Float, ty As Float)
   If Not(Action = Activity.ACTION_DOWN) Then Return
   If tx > x - boxSize AND tx < x + boxSize AND _
      ty > y - boxSize AND ty < y + boxSize Then
      vx = -vx 'change the smiley direction if the user pressed on it
      vy = -vy
   End If
   CircleCanvas.DrawCircle(tx, ty, 5dip, Colors.Red, False, 2dip)
   Activity.Invalidate3(tx - 7dip, ty - 7dip, tx + 7dip, ty + 7dip)
End Sub

Is this correct for Game view:

B4X:
Sub gv_Touch (Action As Int, X As Float, Y As Float)
If Not(Action = Activity.ACTION_DOWN) Then Return
   If X > smiley.DestRect.Right - size AND X < smiley.DestRect.Right AND _
      Y > smiley.DestRect.Bottom - size AND Y < smiley.DestRect.Bottom Then
      vx = -vx 'change the smiley direction if the user pressed on it
      vy = -vy
       
   End If
gv.Invalidate3(X - 7dip, Y - 7dip, X + 7dip, Y + 7dip)
      
End Sub
[/CODE]

I think something is wrong probably.
 
Upvote 0

Vabzboy

Member
Licensed User
Longtime User
In which way doesn't it work perfectly?

Well.. In the original Smiley app where the Canvas is used.. I find the Ball is reacting much better when touched than it is in the GameviewSmiley app.
 

Attachments

  • Gameview Smiley.zip
    9.2 KB · Views: 212
Upvote 0
Top