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".
ApplicationWindow {
id: arcadeLauncher
// Our boolean
property bool yokoCurrentSurTypeIsYoko: true
width: 640
height: 240
visible: true
Item {
id: test
Keys.onSpacePressed: {
// Switches boolean from true to false or false to true
if (yokoCurrentSurTypeIsYoko) {
yokoCurrentSurTypeIsYoko = false;
} else {
yokoCurrentSurTypeIsYoko = true;
}
}
// Pressing Del resumes the animation
Keys.onDeletePressed: {
yokoSurTypeIndicatorAnim.resume();
}
// Our sprite
AnimatedSprite {
id: yokoSurTypeIndicatorAnim
// initial state
x: 0
y: 0
z: 0
running: true;
// Sprite size
width: 52
height: 17
frameWidth: 52
frameHeight: 17
// Source picture
source: "qrc:/images/Y_surtypeindicator___sprite_board___26-200___78-217.png"
// # of frames, animation speed, transition
frameCount: 16
frameDuration: 100
interpolate: false
// Check each frame to stop on the correct one
onCurrentFrameChanged: {
if (yokoCurrentSurTypeIsYoko) {
if (currentFrame == 0) {
pause();
}
}
if (!yokoCurrentSurTypeIsYoko) {
if (currentFrame == 8) {
pause();
}
}
}
}
}
}
ApplicationWindow {
id: arcadeLauncher
// Our boolean
property bool yokoCurrentSurTypeIsYoko: true
width: 640
height: 240
visible: true
Item {
id: test
Keys.onSpacePressed: {
// Switches boolean from true to false or false to true
if (yokoCurrentSurTypeIsYoko) {
yokoCurrentSurTypeIsYoko = false;
} else {
yokoCurrentSurTypeIsYoko = true;
}
}
// Pressing Del resumes the animation
Keys.onDeletePressed: {
yokoSurTypeIndicatorAnim.resume();
}
// Our sprite
AnimatedSprite {
id: yokoSurTypeIndicatorAnim
// initial state
x: 0
y: 0
z: 0
running: true;
// Sprite size
width: 52
height: 17
frameWidth: 52
frameHeight: 17
// Source picture
source: "qrc:/images/Y_surtypeindicator___sprite_board___26-200___78-217.png"
// # of frames, animation speed, transition
frameCount: 16
frameDuration: 100
interpolate: false
// Check each frame to stop on the correct one
onCurrentFrameChanged: {
if (yokoCurrentSurTypeIsYoko) {
if (currentFrame == 0) {
pause();
}
}
if (!yokoCurrentSurTypeIsYoko) {
if (currentFrame == 8) {
pause();
}
}
}
}
}
}
To copy to clipboard, switch view to plain text mode
Yours,
--Jay
Bookmarks