Skip to content

Commit

Permalink
refined the snap animation
Browse files Browse the repository at this point in the history
  • Loading branch information
ThasianX committed Aug 1, 2020
1 parent 06a307b commit bf744d9
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,20 @@ private extension ColorNode {

private extension ColorNode {

// TODO: fix this for the first node. it can be really snappy
func snap(to location: CGPoint, multiplier: CGFloat, completion: @escaping () -> Void) {
guard position != location else { return }

let offset = CGPoint(x: -position.x,
y: -position.y)
let offset = CGPoint(x: location.x - position.x,
y: location.y - position.y)
let snapVector = CGVector(dx: offset.x*multiplier,
dy: offset.y*multiplier)
physicsBody?.velocity = snapVector

let distance = hypot(offset.x, offset.y)
let moveDuration = 0.001*distance

let moveAction = SKAction.move(to: location,
duration: 0.25)
duration: TimeInterval(moveDuration))

run(moveAction, completion: completion)
}
Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion SwiftUIExample/SwiftUIExample/SwiftUIExampleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct CustomNodeStyle: NodeStyle {

func apply(configuration: Configuration) -> ColorNode {
configuration.defaultStyledNode
.radius(35)
.radius(30)
.font(name: "Thonburi")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct CustomNodeStyle: NodeStyle {

func apply(configuration: Configuration) -> ColorNode {
configuration.defaultStyledNode
.radius(35)
.radius(30)
.font(name: "Thonburi")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct CustomNodeStyle: NodeStyle {

func apply(configuration: Configuration) -> ColorNode {
configuration.defaultStyledNode
.radius(35)
.radius(30)
.font(name: "Thonburi")
}

Expand Down

0 comments on commit bf744d9

Please sign in to comment.