Interested in how you can implement the following:

There is an object, it is created in an absolutely random place on the screen. And this object needs to reach a certain point. How can this be described? Calculate every step?

As well as how to implement a tap check on an object. Objects I have usual canvas with bmp image stretched on them

    2 answers 2

    This can be done using ObjectAnimator . Define inside your view that draws an object. and with each animation tick ( addUpdateListener ) you make invalid views. And how exactly to implement the animation depends on what you want to achieve. You can change the Rect bitmapki, you can translate the canvas. The trajectory itself is set using the TypeEvaluator .

    Regarding tapa on an object, you draw it in a certain Rect on the canvas. So the Rect has a contains method. You pass the position of the finger into it and find out whether it is a rect finger inside or not.

    • Well, roughly speaking, on each tick, I just need to calculate by 2 points of the object that moves and by 2 points of the destination, calculate how much to change the position of the object that moves. In this case, it would be good to rotate an object that moves towards the destination. - ParanoidPanda
    • Rotate you can also change ObjectAnimator. You can either have one animator to do this or different. And so in Evaluator you get fractions, this relative animation time is usually from 0 to 1, it is calculated using Interpolator. And 2 objects in your case it will be two points. Start point and end point. Depending on the trajectory, calculate by the two points and fractions the position of the current point and return it. ObjectAnimator will transfer this point to the object that you pass to it with the first parameter. It will call the setPROPERTY_NAME method. - Mikhail

    If you do not use any animators, then yes consider each step. Point classes Point2D and Point3D have a good midpoint method. You can create a trajectory by building it from mid-points with the necessary detail (the calculation of the distance between the points is also available for these classes).