Skip to content

Can't stop content animation #97

Closed
@zapletnev

Description

@zapletnev
import Foundation
import Macaw

class StudioView: MacawView {
    
    required init?(coder aDecoder: NSCoder) {
        super.init(node: Group(contents: []), coder: aDecoder)
        
        let animationGroup = Group(contents: [])
        let animation = animationGroup.contentsVar.animation({ t in
            let shape = Shape(
                form: Arc(
                    ellipse: Ellipse(
                        cx: (Double(self.bounds.width) / 2),
                        cy: (Double(self.bounds.height) / 2),
                        rx: 150.0, ry: 150.0),
                    shift: 0,
                    extent: 2 * M_PI * t
                ),
                stroke: Stroke(fill: Color.red, width: 4)
            )
            return [shape]
        })
        
        let playBtn = Shape(
            form: Rect(
                x: Double(self.bounds.width) / 2 - 50,
                y: Double(self.bounds.height) / 2 - 50,
                w: 100, h: 100
            ),
            fill: Color.red
        )
        
        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 count: Int = 0
        playBtn.onTap { _ in
            if count % 2 == 0 {
                count = count + 1
                print("START!")
                animation.play()
            } else {
                print("STOP!")
                animation.stop()
            }
        }
        self.node = [playBtn, text, animationGroup].group()
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions