OnObjectUpdate
method gives you the object as a parameter.Method OnObjectUpdate:Int(obj:ftObject)
SELECT
operation on the obj
variable:Select obj
g.ball
, it is our ball:Case g.ball
If (obj.yPos < obj.GetHeight()/2 And obj.GetSpeedY() < 0) Or (obj.yPos > (g.ch - obj.GetHeight()/2) And obj.GetSpeedY() > 0) Then
Y
speed factor so it will bounce off the edge. Also play the Hit sound effect:obj.SetSpeedY(-obj.GetSpeedY()) g.sndHit.Play() Endif
If (obj.xPos < obj.GetWidth()/2 And obj.GetSpeedX() < 0) Or (obj.xPos > (g.cw - obj.GetWidth()/2) And obj.GetSpeedX() > 0) Then
X
speed factor, so it will bounce off the edge. Also play the Hit sound effect:obj.SetSpeedX(-obj.GetSpeedX()) g.sndHit.Play() Endif
GetAccelXY
method, you can simulate these by using the up, down, left, and right keys. That is great for testing. ac
array:Local ac:Float[] = g.eng.GetAccelXY()
x
or the y
value is different from 0:
If ac[0]<> 0.0 Or ac[1]<> 0.0 Then
ac
array:ac[0] += obj.GetPosX() ac[1] += obj.GetPosY()
1
into the direction, which will be calculated from the object's position to the previous coordinates:obj.AddSpeed(1,obj.GetVectorAngle( ac[0], ac[1] )) Endif End Return 0 End
In this method, we are now controlling the ball object. It will bounce off the edges of the screen and we will be able to control it on the device by tilting it, or by the arrow keys on the keyboard if we are on a desktop.