Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Compose SpriteKit animations quickly in a declarative SwiftUI-style

License

NotificationsYou must be signed in to change notification settings

coughski/ActionBuilder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Caveat developer: As this package is pre-release, the API may change significantly without notice. It has not been tested, so use it at your own risk.

ActionBuilder allows you to write SpriteKit animations in a more succinct, declarative manner. It consists of various structs representing basic animations likeScale andRotate.

An animation created with ActionBuilder:

letemote=Sequence{Group{FadeIn(duration:0.7)Scale(by:1.5, duration:0.7)Move(to:(0,30), duration:0.7)}Wait(0.5)FadeOut(duration:1)Remove()}

Versus the same animation using Apple's SpriteKit SKActions:

letemoteAction:SKAction={letfadeIn=SKAction.fadeIn(withDuration:0.7)letgrow=SKAction.scale(by:1.5, duration:0.7)letmoveUp=SKAction.moveTo(y:30, duration:0.7)letappear=SKAction.group([fadeIn, grow, moveUp])letwait=SKAction.wait(forDuration:1)letdisappear=SKAction.fadeOut(withDuration:1)letremove=SKAction.removeFromParent()letemoteAnimation=SKAction.sequence([appear, wait, disappear, remove])return emoteAnimation}()

ActionBuilder allows you to use conditional and looping statements within your animation declaration to make them more flexible and easier to write.

Coordinate animations across multiple nodes with thechangeTarget(to:) modifier.

Custom operators included:+ will concatenate actions into a sequence,& will group them to run simultaneously,- will reverse reversible actions, and* allows you to repeat an action multiple times.

You can even includeSKActions if no equivalent is available in ActionBuilder.

letnode=SKNode()letotherNode=SKNode()node.run{Group{Sequence{foriin0...9{Colorize(with:UIColor(red:Double(i/10), green:0.7, blue:0.7, alpha:1))Wait(0.2)}}.changeTarget(to: otherNode)Sequence{letmoveUp=Move(by:(0,10))ifBool.random(){                moveUp*2}else{-moveUp}SKAction.resize(toHeight:20, duration:5)}}}

See Apple's documentation:https://developer.apple.com/documentation/spritekit/skaction/action_initializers


[8]ページ先頭

©2009-2025 Movatter.jp