Android Question move Image, Textbox

FrankDev

Active Member
Licensed User
Longtime User
Hi guys,

how can I move an image or textbox.
Clearly with 'setlayoutanimated'.
but:
I want to make it circle for example, or use a bounce effect.
Is it possible to link a movement to some kind of path. ?

Best regards
Frank
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Create list of points on the curve you want, Then use .Left and .Top on any B4XView to iterate through the path.
Use sleep(...) to delay moving to the next point.

I haven't done it but you can use the Turtle system to get the points.
But you could also (as I have done many times), use trigonometry and math

Given a radius = r , iterate angle through 360 degrees, and use x = r * cosD(angle) and y = r * sinD(angle)
This will provide a list of points on a circle centered at (0, 0). So you have add offsets for x and y.

Edit: you can save a lot of time with Type Point(x As float, y As Float)
 
Upvote 0

FrankDev

Active Member
Licensed User
Longtime User
it's not quite clear to me yet how to do that.
Do I write this into an array ?
When I push a straight line along, I need maybe 100 points.
is that then still smooth ?
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
No Array.
Use a list of points (see above Type). Make the number of points (in a circle the # of angle increments) a variable so you can test what makes it smooth.
For animation you also need to experiment with Sleep().

To make it easier...
For Type Point, create SetPoint to create a point and CopyPoint to copy it.
You can also make a sub called PointsDistance (Power(Sqrt(x1-x2), 2) + Power(y1-y0, 2)))

For inspiration see:
https://www.b4x.com/android/forum/threads/b4x-text-along-any-curve.138639/
 
Upvote 0
Top