Results 1 to 2 of 2

Thread: AnimatedSprite NOT resuming but restarting instead?!

  1. #1
    Join Date
    Sep 2015
    Posts
    32
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default AnimatedSprite NOT resuming but restarting instead?!

    Ok this next one is driving me crazy : )

    I have an AnimatedSprite and a boolean variable.
    The animated sprite contains 16 frames total.
    If the boolean is true, I want the animation to stop on the very first frame (when currentFrame == 0).
    If the boolean is false, I want the animation to stop on the 8th frame (when currentFrame ==8).

    Two keyboard keys control the animation:
    Space changes the boolean from true to false and from false to true.
    Del resume the AnimatedSprite.
    The animation is in a "running" state by default.

    I never stop the animation. I only ever use "pause();".
    But somehow the animation restart from the BEGINNING in certain instances.

    **DropBox link of my sprite in case you want to test**
    https://www.dropbox.com/s/2hm9i891it...8-217.png?dl=0




    Behavior observed:
    App start. Boolean is set to true -> Animation is stopped (I guess "paused") on Frame == 0. -> OK everything is fine so far.
    Press SPACE -> Boolean changes from true to false (it's logged, so I know it actually happens) -> Press Del -> Animation resume and STOPS at frame 8 -> OK everything is fine so far.
    Press SPACE -> Boolean changes from false to true (it's logged, so I know it actually happens) -> Press Del -> The Animation DOES NOT resume. It RESTARTS from frame 0 and STOPS at frame 0 -> What the heck is happening?!? Why does it not resume from where it last paused ?!

    I also tried:
    App start. Boolean = true.
    Press space TWICE. Press del. -> The animation cycles around as it should

    And also:
    App start. Boolean = true.
    Press space. Press del. -> The animation stops at frame 8 as it should
    Press space TWICE. Press Del -> Animation RESTARTS : (



    What am I doing wrong?
    What don't I understand?
    Ps: in my previous code I also logged each frame we "passed on" and when the animation restarted instead of resuming, I could see that the frame 9th to 15th were NEVER "browsed".


    Qt Code:
    1. ApplicationWindow {
    2. id: arcadeLauncher
    3.  
    4. // Our boolean
    5. property bool yokoCurrentSurTypeIsYoko: true
    6.  
    7. width: 640
    8. height: 240
    9. visible: true
    10.  
    11. Item {
    12. id: test
    13. Keys.onSpacePressed: {
    14. // Switches boolean from true to false or false to true
    15. if (yokoCurrentSurTypeIsYoko) {
    16. yokoCurrentSurTypeIsYoko = false;
    17. } else {
    18. yokoCurrentSurTypeIsYoko = true;
    19. }
    20. }
    21.  
    22. // Pressing Del resumes the animation
    23. Keys.onDeletePressed: {
    24. yokoSurTypeIndicatorAnim.resume();
    25. }
    26.  
    27. // Our sprite
    28. AnimatedSprite {
    29. id: yokoSurTypeIndicatorAnim
    30.  
    31. // initial state
    32. x: 0
    33. y: 0
    34. z: 0
    35. running: true;
    36.  
    37. // Sprite size
    38. width: 52
    39. height: 17
    40. frameWidth: 52
    41. frameHeight: 17
    42.  
    43. // Source picture
    44. source: "qrc:/images/Y_surtypeindicator___sprite_board___26-200___78-217.png"
    45.  
    46. // # of frames, animation speed, transition
    47. frameCount: 16
    48. frameDuration: 100
    49. interpolate: false
    50.  
    51. // Check each frame to stop on the correct one
    52. onCurrentFrameChanged: {
    53. if (yokoCurrentSurTypeIsYoko) {
    54. if (currentFrame == 0) {
    55. pause();
    56. }
    57. }
    58.  
    59. if (!yokoCurrentSurTypeIsYoko) {
    60. if (currentFrame == 8) {
    61. pause();
    62. }
    63. }
    64.  
    65. }
    66. }
    67. }
    68. }
    To copy to clipboard, switch view to plain text mode 


    Yours,
    --Jay
    Last edited by JaySDC; 21st September 2015 at 09:57.

  2. #2
    Join Date
    Sep 2015
    Posts
    32
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: AnimatedSprite NOT resuming but restarting instead?!

    Ok this is f***** up!

    If frameSync = true, then the very same code works as intended.

    Which is a freaking shame because that means that I can't choose the speed at which the animation is ran...


    Any idea how to achieve that ?

    Yours,
    --Jay

Similar Threads

  1. Replies: 4
    Last Post: 13th September 2015, 14:51
  2. How to use QTimer for pausing and resuming ?
    By qt_user_154 in forum Qt Programming
    Replies: 7
    Last Post: 26th August 2013, 12:40
  3. Replies: 1
    Last Post: 2nd November 2012, 07:56
  4. Replies: 19
    Last Post: 21st January 2008, 09:13

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
  •  
Qt is a trademark of The Qt Company.