Android Question Is it possible to give gravity (Physics Gravity) to a lable or image view?

Rajesh kannan MJ

Member
Licensed User
Longtime User
Hi,

Is it possible to assign graviity (Physics game gravity) to a label or text box or image view?

Actually, My aim is to make simple and smooth animations of image view or text area. So, without using libgdx, I want to animate and do some smalll gamings.

Thank you in advance,
 

walterf25

Expert
Licensed User
Longtime User
Hi,

Is it possible to assign graviity (Physics game gravity) to a label or text box or image view?

Actually, My aim is to make simple and smooth animations of image view or text area. So, without using libgdx, I want to animate and do some smalll gamings.

Thank you in advance,
You can use the AnimationLib to animate a simple label, just do a search for "Animation Library" in the search box.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
Also try AnimationPlus library using which you can set animation interpolators like bounce, overshoot, accelerate etc.. which will simulate gravity to a small level
 
Upvote 0

wonder

Expert
Licensed User
Longtime User
My game physics are based on this simple example: http://jsfiddle.net/LyM87/
Although it's JAVA code, it's simple enough to be understood and ported to B4A.

Gravity basically works like this:
B4X:
Dim gravity = (9.8 / 60) AS Float
Dim velocityY = 0 AS Float
Dim positionY = 0 AS Float
Label1.Top = positionY

Do
      'The object will fall until it reaches the bottom of the screen.
      'Assuming that this loop runs 60 times per second, your object
      'will accelerate 9.8 pixels per second, every second.

      If positionY < (100%y - Label1.Height) then
            velocityY = velocityY + gravity
            positionY = positionY + velocityY;
            Label1.Top = positionY
      Else
            Label1.Top = (100%y - Label1.Height)
      End If
Loop

Disclaimer: This code wasn't tested nor should it be implemented as is.
This is more like pseudo-basic-code. You're better off using a Timer(16ms) rather than a Do...Loop cycle.
 
Last edited:
Upvote 0
Top