Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Away all Goats
Jul 5, 2005

Goose's rebellion

I'm doing an exercise on tween animations of the earth orbiting around the sun. For some reason I cannot get the earth to pivot around the image of the sun, only itself. Can someone tell me what I'm doing wrong?

code:
class ExerciseThree: AppCompatActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.exercise03)

        // Find the image views in the layout
        val sunImageView = findViewById<ImageView>(R.id.imageSun)
        val earthImageView = findViewById<ImageView>(R.id.imageEarth)

        // Set up the orbit path animation
        earthImageView.pivotX = sunImageView.x + sunImageView.width / 2f
        earthImageView.pivotY = sunImageView.y + sunImageView.height / 2f

        // Set up the orbit animation
        val orbitAnimation = ObjectAnimator.ofFloat(
            earthImageView,
            "rotation",
            0f,
            360f
        ).apply {
            duration = 4000 // Set the duration of the animation to 4 seconds
            repeatCount = ObjectAnimator.INFINITE // Set the animation to repeat infinitely
            interpolator = LinearInterpolator() // Use a linear interpolator to keep the speed constant
        }

        // Start the orbit and orbit path animations
        orbitAnimation.start()

    }
I have the two images constrained properly, with the sun in the very center and the earth starting right above it.

Adbot
ADBOT LOVES YOU

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply