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.


    Why does this flicker?

    Pythonista
    2
    2
    1752
    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.
    • Webmaster4o
      Webmaster4o last edited by

      I've written some incredibly basic code for a custom view class that can be dragged/dropped.

      class DragDrop(ui.View):
      	def touch_moved(self, touch):
      		tx, ty = touch.location
      		self.x,self.y = tx-self.frame[2]/2, ty-self.frame[3]/2
      
      v=ui.View()
      dnd = DragDrop(frame=(100,100,100,100))
      dnd.background_color=(0,0,0)
      v.add_subview(dnd)
      v.present(hide_title_bar=1)
      

      However when I drag an object, its position flickers between two positions. Why is this, and how can I fix it?

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

        Touch position changes in the touch_moved method between calls (yeah bear with me that ones kinda obvious) but what I mean is that moving your finger from top left to bottom right on each move there is two changes for some reason. (0,0) and (0,-1) simultaneously hence the flicker.
        This is shown simply by printing to touch coordinats.

        print tx, ty
        

        Solution: find delta x and delta y (ie the change from the current position and the last position)

        class DragDrop(ui.View):
            def touch_moved(self, touch):
                cx, cy = touch.location
                ox, oy = touch.prev_location
                tx, ty = ox-cx, oy-cy
                print tx, ty
                self.x -= tx
                self.y -= ty
        
        1 Reply Last reply Reply Quote 1
        • First post
          Last post
        Powered by NodeBB Forums | Contributors