Results 1 to 2 of 2

Thread: Jumping with QGraphicsItem[Python]

  1. #1

    Default Jumping with QGraphicsItem[Python]

    I am trying to make QGraphicsItem jump with keys.

    Here is code which reads pressed key from user (this is working):

    I don't really know how I should create the jump_up() function here, this code won't work, because while -loops iterates so fast it goes
    straight to the floor.

    Qt Code:
    1. def keyPressEvent(self, QKeyEvent):
    2. self.key = QKeyEvent.key()
    3. self.pressedkeys[self.key] = True
    4.  
    5. def keyReleaseEvent(self, QKeyEvent):
    6. self.key = QKeyEvent.key()
    7. self.pressedkeys[self.key] = False
    8.  
    9. def key_action(self):
    10. for self.key, is_pressed in self.pressedkeys.items():
    11.  
    12. if is_pressed:
    13. print("x")
    14. if self.key == QtCore.Qt.Key_D:
    15.  
    16. self.game.newplayer.move_forward()
    17. self.update()
    18. elif self.key == QtCore.Qt.Key_W:
    19. self.game.newplayer.jump_up() #calling here for jump function!
    20. self.update()
    21.  
    22. def jump_up(self):
    23. grav = 5
    24. self.item.moveBy(0, self.jumpacc)
    25. while self.get_ylocation() < 0: #while rect is not touching the floor move the rect towards floor
    26. self.item.moveBy(0, grav)
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,531
    Thanks
    13
    Thanked 1,576 Times in 1,505 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Jumping with QGraphicsItem[Python]

    What should jump_up() do? Are you expecting a smooth transition over time up the screen followed by one downward?

Similar Threads

  1. Replies: 1
    Last Post: 30th January 2017, 11:42
  2. Embedding PyQt4 into an Application running Python via Boost::Python
    By GreyHound in forum Installation and Deployment
    Replies: 1
    Last Post: 6th February 2012, 06:48
  3. Jumping/stuttering during animation QPainter
    By ghm in forum Qt Programming
    Replies: 0
    Last Post: 6th November 2011, 10:51
  4. Replies: 0
    Last Post: 8th April 2011, 20:10
  5. Replies: 7
    Last Post: 29th November 2010, 19:20

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.