Android Question Tracking position of animation object

zetadan

Member
Licensed User
Longtime User
How do I track the position of an animation during the animation event?

I am using Erel's tutorial code:

B4X:
Dim a1, a2, a3, a4, a5 As Animation
    Activity.LoadLayout("1")
    a1.InitializeAlpha("", 1, 0)
    Button1.Tag = a1
    a2.InitializeRotate("", 0, 180)
    Button2.Tag = a2
    a3.InitializeRotateCenter("", 0, 180, Button3)
    Button3.Tag = a3
    a4.InitializeScale("", 1, 1, 0, 0)
    Button4.Tag = a4
    a5.InitializeScaleCenter("", 1, 1, 0, 0, Button4)
    Button5.Tag = a5
    a6.InitializeTranslate("Animation", 0, 0, 0dip, 200dip) 'we want to catch the AnimationEnd event for these animations
    a7.InitializeTranslate("Animation", 0dip, 200dip, -200dip, 200dip)
    a8.InitializeTranslate("Animation", -200dip, 200dip, -200dip, 0dip)
    a9.InitializeTranslate("Animation", -200dip, 0dip, 0dip, 0dip)
    Button6.Tag = a6
    animations = Array As Animation(a6, a7, a8, a9)
    For i = 0 To animations.Length - 1
        animations(i).Duration = 500
    Next
Dim animations() As Animation
    animations = Array As Animation(a1, a2, a3, a4, a5)
    For i = 0 To animations.Length - 1
        animations(i).Duration = 1000
        animations(i).RepeatCount = 1
        animations(i).RepeatMode = animations(i).REPEAT_REVERSE
    Next
Sub Button_Click
    Dim b As Button
    b = Sender
    'Safety check. Not really required in this case.
    If Not(b.Tag Is Animation) Then Return
    Dim a As Animation
    a = b.Tag
    a.Start(b)
End Sub
 

zetadan

Member
Licensed User
Longtime User
I am trying to interact with the object in a game like mode. It is a simple interaction where I just want to stop the animation when two objects collide. The second being a view controlled by the user.
 
Upvote 0

zetadan

Member
Licensed User
Longtime User
Erel, Thanks so much for the input.

This is not a game per say. The movement I am trying to interact with is very simplistic. I am thinking of using a timer to locate where the view is during the animation. Then I could perform the math to determine whether both views occupy the same space. Unless you advise me that this idea is totally unworkable, I will try it.

Do you think I have a chance of making this work?
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Upvote 0

eps

Expert
Licensed User
Longtime User
and this from Informatix

HTH

Detect collisions accurately

When two objects move in the same area, there’s a chance that they collide. It’s what you expect from your bullets when you shoot at a monster. But how to detect whether 2D objects are actually colliding?

There’s a very simple answer: use the specialized functions of a physics engine. They are very good at anticipating, detecting and handling a collision between two solid bodies. I admit that they are not always easy to use and beginners may want to stay away. So what to do?

The most used technique is the detection of overlapping AABBs. AABB means “axis-aligned bounding box” and is a rectangle around the visual boundaries of an object. If two AABBs overlap, there’s a collision. That’s fine if the two shapes in the AABBs are more or less rectangular. Let’s see an example. This “angry car” image has a lot of empty space around it:

http://www.b4x.com/android/forum/threads/how-to-make-games.32593/
 
Upvote 0
Top