omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Bug using gravity() during setup

    Pythonista
    2
    3
    2471
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Scatterfelt
      Scatterfelt last edited by

      I've been using gravity() during a scene's setup to establish the starting position of the device. It works great on my iPad Air. My iPhone 5, however, doesn't seem to get any values from gravity() when run during setup.

      To test this, check out the following code: https://gist.github.com/andrewschmidt/8293953

      Run on my iPad Air, tilted mostly vertical, this outputs:
      (0.01366471778601408, -0.8423394560813904)

      Run on my iPhone 5, in any position:
      (0.0, 0.0)

      It's worth noting that in my actual script, the gravity() call made after the scene has begun looping works fine on the iPhone. It's only in setup that it doesn't return anything.

      I don't know which is the intended behavior, but it can't be both!

      1 Reply Last reply Reply Quote 0
      • Scatterfelt
        Scatterfelt last edited by

        And I'm back a couple minutes later with a discovery.

        I added a hack-y bit of code—I stuck the gravity() call in a WHILE loop that doesn't end until it gets values different than zero.

        This mostly solved the problem on my iPhone. Based on just how it feels to use gravity() to move a rect around, it seems like the accelerometer takes a second or two after it begins returning values to return correct values. I wouldn't expect Pythonista to do anything about that—it's just something devs will have to be aware of.

        In summary: Looks like the iPhone 5 is a bit slower about either getting gravity() up and running, or getting values from the system's accelerometer. A little too slow to get any information before a scene has finished with setup.

        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          What happens if you add a call to time.sleep(0.001) as the first line of your scene.Scene.setup() method?<br />Or time.sleep(1) or time.sleep(3)?

          Also, scene.Vector3 has two undocumented methods: as_tuple() and todict().

          print(scene.gravity().as_tuple())
          print('x: {x}\ny: {y}\nz: {z}'.format(**scene.gravity().todict()))
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors