Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't stop animation with delay #102

Closed
zapletnev opened this issue Feb 17, 2017 · 0 comments
Closed

Can't stop animation with delay #102

zapletnev opened this issue Feb 17, 2017 · 0 comments
Assignees
Labels
Milestone

Comments

@zapletnev
Copy link
Contributor

stop() function doesn't have an effect

import Foundation
import Macaw

class StudioView: MacawView {
    required init?(coder aDecoder: NSCoder) {
        super.init(node: Group(contents: []), coder: aDecoder)
        
        let rect = Rect(
            w: 50.0,
            h: 50.0
        )
        
        let soundBase = Shape(
            form: rect,
            fill: Color.red
        )
        soundBase.place = Transform.move(dx: Double(self.bounds.width) / 2.0 - 25, dy: Double(self.bounds.height) / 2.0 - 25)
        
        let text = Text(
            text: "START",
            align: .mid,
            place: Transform.move(
                dx: (Double(self.bounds.width) / 2),
                dy: (Double(self.bounds.height) / 2)
            ),
            opaque: false
        )
        
        var animation: Animation!
        
        var count: Int = 0
        soundBase.onTap { _ in
            if count % 2 == 0 {
                animation = Array(0...10).map { index in
                    return [
                        soundBase.opacityVar.animation(to: 1.0, during: 0.1),
                        soundBase.opacityVar.animation(to: 0.0, during: 0.1)
                    ].sequence().delay(Double(index))
                }.combine()

                text.text = "STOP!"
                print("START!")
                animation.play()
            } else {
                print("STOP!")
                text.text = "START!"
                animation.stop()
            }
            count = count + 1
        }
        
        self.node = [soundBase, text].group()
      }
}  
@zapletnev zapletnev added the bug label Feb 17, 2017
@ystrot ystrot added this to the 0.8.1 milestone Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants