Store a view's position

squaremation

Active Member
Licensed User
Longtime User
I am trying to have animation go to a target, and need the targets position to end the animation.

I tried this, but it only sends the object to the upper left corner, I am pretty sure I am not it's just not getting the x and y position stored correct.

This is resolved I was using the position of image I wanted to move, instead of the target, and imputing the variable back wards (my own stupidity) :BangHead: althought the multiple animation with a single object is not producing the desired effect, think I will got with lines instead:confused:

this should be:
B4X:
   tx = imvTarget.Top  + 32  '***attempt to store the 'targets' position***
   ty = imvTaget.Left  + 65   'added the equation to center it


B4X:
Sub Globals
   'shots
   Dim imvShot1 As ImageView 
   Dim Button1 As Button
   Dim  tx, ty As Float 
   Dim a6, a7, a8, a9 As Animation
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout(1)
   a6.InitializeTranslate("Animation", 0, 0, tx/4, ty/4)
   a7.InitializeTranslate("Animation", tx/4, ty/4, tx/3, ty/3) 
   a8.InitializeTranslate("Animation", tx/3, ty/3, tx/2, ty/2) 
   a9.InitializeTranslate("Animation", tx/2, ty/2, tx, ty)
   
   imvShot1.Tag = a5
   animations = Array As Animation(a6, a7, a8, a9)
   For i = 0 To animations.Length - 1
      animations(i).Duration = 500
   Next
End Sub

Sub Fire_Click
   Dim b As Button
   Fire = Sender
   imvShot1.Top = tx     '***attempt to store the 'targets' position***
   imvShot1.Left  = ty

   If Not(imvShot1.Tag Is Animation) Then Return
   Dim A As Animation
   A = imvShot1.Tag
   A.Start(imvShot1)
End Sub
 
Last edited:

squaremation

Active Member
Licensed User
Longtime User
still trying to figure this out any insight appreciated

latest fail :BangHead:
B4X:
Sub Button1_Click 
        Dim tX, tY, ex, eY, x1, y1, x2, y2, f1, f2, f3, f4 As Double
   Dim sW, sH As Int
   'get sprite dimentions
   sW = sprMain.SpriteWidth / 2
   sH = sprMain.SpriteHeight / 2
   'get target positions
   tX = objMain.XPosition 
   tY = objMain.YPosition 
   'get enemy positions
   ex = objEnmy.XPosition 
   eY = objEnmy.YPosition 
   'variables set demintions to a square inside target
   x1 = tX + (sW - 5)
   y1 = tY + (sH - 5)
   x2 = tX - (sW - 5)
   y2 = tY - (sH - 5)
   'checks if x and y of enemy object is with square
   If ex > x1 Then f1 =1
   If ex < x2 Then f2 =1
   If eY > y1 Then f3 =1
   If eY < y2 Then f4 =1
   
   If f1 + f2 + f3 + f4 = 4 Then
      explodeFX
   End If
End Sub

Using RSGameEngine Library
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
You do not say what is happening so it is hard to help.

What does stand out is that if x1, y1, x2 and y2 are meant to be a square with the centre being the centre of the target, then

B4X:
x2 = tX + (sW - 5)
y2 = tY + (sH - 5)

is correct - top plus half size minus five and left plus half size minus five.
 
Upvote 0
Top