Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
用SpriteKit 做一個FB 投籃遊戲
Search
Johnlin
April 12, 2016
Programming
210
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
用SpriteKit 做一個FB 投籃遊戲
Johnlin
April 12, 2016
More Decks by Johnlin
See All by Johnlin
用 MLIR 實作 一個 Ruby IR (intermediate representation)
johnlinvc
0
340
Unearth Ruby builtin Gems 發掘 Ruby 的內建 Gems
johnlinvc
0
430
Ruby 型別檢查工具簡介
johnlinvc
0
650
Swift Actor 實作探索
johnlinvc
0
210
用 mruby 來寫跨平台工具
johnlinvc
0
130
Actor model 簡介
johnlinvc
0
250
一起玩 Helm 3
johnlinvc
1
170
為什麼 App 卡卡的
johnlinvc
2
1.3k
如何使用 byebug 來除錯 Ruby 程式
johnlinvc
0
280
Other Decks in Programming
See All in Programming
Are APIs Still Relevant in the AI Era?
soyuka
0
280
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.4k
AI × TiDD / 2026.09.05 Redmine 大阪
tokudiro
1
180
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
160
WebAssembly in Android Apps 〜 WASMはJNIの夢を見るか
keiji
1
110
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
240
cdk deploy JawsSonic #MARATHONしながらAWSリソースをデプロイしてみよう
akihisaikeda
2
140
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
380
Heart of Swift Concurrency
koher
0
930
一人だけ、Kiroが静止する日
hideg
0
120
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
150
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.1k
Featured
See All Featured
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Amusing Abliteration
ianozsvald
1
310
The Curse of the Amulet
leimatthew05
3
15k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
710
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
370
Building the Perfect Custom Keyboard
takai
2
880
Practical Orchestrator
shlominoach
192
12k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
530
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Optimizing for Happiness
mojombo
378
71k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
3
3.8k
Transcript
༻SpriteKit ၏ҰݸFB ឈ༡ፍ John Lin @johnlinvc
SpriteKit • Apple ։ᚙత2D ༡ፍᐽՍɼࢧԉiOS & OSX • แؚ៸ᅷɼཧٖɼӨԻ
FB ឈ༡ፍ
Ꮠ ឈᐽ ឈٿ
༡ፍྲྀఔ • ឈ • ఁଌ༗ᔒ༗ਐ • ᰖࣔᏐ
SKView • UIView త Subclass • ෛመࡍత៸ᅷ • ՄҎᰖࣔҰࠣআࡨ༻తࢿ㘤
SKScene • ෛ႔ཧ༡ፍతҰݸܠɻ • ෛ႔ཧಈᙘᢛཧٖɻ • ༻ SKView.presentScene ိᰖࣔ •
ݐٞࡏ didMoveToView தݐཱመࡍత݅
SKNode • ද༡ፍதత݅ɼՄҎੋᅷยɼจࣈɼܗ㐫ɼӨԻ • SKScene ੋSKNode త subclass • ݸ༡ፍதత݅ੋҰݸथ㐫݁ߏɼrootबੋ
SKScene
SKLabelNode • ᰖࣔจࣈ༻ • ༻ိᙘ
ఁଌख • SKNode ੋ UIResponder త subclass • ༻ touchesBegan(_:withEvent:)
ိܭࢉىᴍ • ༻ touchesEnded(_:withEvent:) ိܭࢉऴᴍ • ၷݸ૬ݮबՄҎፙग़खతํ
SKPhysicsBody • 㑌ݸSKNode ՄҎ༗Ұݸ physicsBody ိਐߦ ཧٖɻ • ՄҎࣗݾఆٛܗ㐫ɼՄҎኺtexture ࣗಈ㗞ੜ
• ՄҎઃఆ֤छཧಛੑɼ࣭ྔɼີɼຎࡲᏐɼኧ ੑᏐɼҠಈ્ྗɼટ્ྗ
㟚ٿ • ҝ߶߶తLabel Ճ্Ұݸᅵܗత physicsBody physicsBody = SKPhysicsBody(circleOfRadius: 95, center:
CGPointMake(0, 75)) • ࡏ㟚ٿલෆཁडॏྗӨڹ physicsBody?.affectedByGravity = false • ሣٿࢪՃҰݸিྔɼฒ⬏ಈॏྗ let impulse = CGVectorMake(base * (dx/norm), base * (dy/norm)) physicsBody?.applyImpulse(impulse) physicsBody?.affectedByGravity = true
None
ឈᐽ • Ұᑍߚઢɼࠨӈၷᬑ༗ఁଌ䉰తეҬ • ՄҎ༻ SKShapeNode ိᙘ ring = SKShapeNode(rect:
CGRectMake(0, 0, rad, 2*h))
ឈᐽ䉰 • ࠨӈ֤ᙘҰᑍឈᐽ let l = SKPhysicsBody(edgeFromPoint: CGPointMake(0, 2*h), toPoint:
CGPointMake(3*h, 2*h)) let r = SKPhysicsBody(edgeFromPoint: CGPointMake(rad-3*h, 2*h), toPoint: CGPointMake(rad, 2*h)) • Ұݸཟᐽ ring!.physicsBody = SKPhysicsBody(bodies: [l,r])
None
ٿؐࡏ্ঋब౸ឈᐽྃ • ҼҝឈᐽҰࡏಹཪɼॴҎ্ঋब။౸ • ղܾํ๏ɿ㭎๏ᩋଞ༗ࡏԼ߱త࣌ީ࠽။౸
༡ፍ㑌ݸᙘ໘త॥
্ঋ࣌ෆཁ䉰 func ballAboveRing()->Bool { return basket?.position.y < ball?.position.y } override
func update(currentTime: NSTimeInterval) { if ballAboveRing() { basket?.ringEnabled = true } }
categoryBitMask:UInt32 & collisionBitMask:UInt32 • ᙛၷݸᱪA,B ᯪۙሣํ࣌ɼ။༻&(bitwise and) ိ ֬ఆၷݸ౦။ෆ။䉰 (a.categoryBitMask
& b.collisionBitMask) && (b.categoryBitMask & a.collisionBitMask) • ҙɿෆੋ༻ძํతcollisionBitMask ိᏗɼ ࣕੋҰํతcategory ሣ্ሣํత collision
ٿઃఆ။౸ᐽ • physicsBody?.categoryBitMask = CollisionMask.Ball physicsBody?.collisionBitMask = CollisionMask.Basket
ᐽՄҎબᎩཁෆཁ䉰 var ringEnabled:Bool { set { ring?.physicsBody?.collisionBitMask = newValue ?
CollisionMask.Ball : CollisionMask.None ring?.physicsBody?.categoryBitMask = newValue ? CollisionMask.Basket : CollisionMask.None } get { return ring?.physicsBody?.collisionBitMask == CollisionMask.Ball } }
ఁଌ༗ᔒ༗ਐ • ෆೳ༻ٿతҐஔိఁଌ • ༻ឈػత၏๏ɼፙग़Ұݸ໋தޙҰఆ။ៃաతᴍ • ༻ҰݸphysicsBoby ိఁଌٿ༗ᔒ༗䉰౸ಹݸᴍ
䉰ఁଌ • ༻ contactTestBitMask & categoryBitMask (a.categoryBitMask & b.contactTestBitMask)
&& (b.categoryBitMask & a.contactTestBitMask) • ༗䉰ᚙੜ࣌။ݺڣ scene.physicsWorld.contactDelegate త didBeginContact(_:) & didEndContact(_:)
መ࡞ܭఁଌث • ᩋఁଌثෆ။౸ٿɼୠੋೳఁଌᢛٿతᨀ phy.collisionBitMask = CollisionMask.None phy.contactTestBitMask = CollisionMask.Ball phy.categoryBitMask
= CollisionMask.Sensor • Լ్߱தɼ䉰౸बՃҰ func didEndContact(contact: SKPhysicsContact) { guard basket!.ringEnabled else { return } score += 1 }
ᰖࣔᏐ var score:Int = 0 { didSet { scoreText?.text =
"Score: \(score)" } }
Bonus: ٻਅመײ • ᩋٿ㟚ग़ڈ೭ޙ။Ꮣখ • ႔ཧٿឈᐽ೭ؒతલޙҐஔ᮫
SKAction • ᩋNodeՄҎํศత၏ग़֤छಈ࡞ɼ૾ੋҠಈɼվᏓ େখɼટ • ՄҎ۲֤छෆಉతಈ࡞ိ၏ग़֤छᏈՌ
ᩋٿᏓখ let scale:CGFloat = 0.5 let scaleDuration:NSTimeInterval = 1.1 runAction(SKAction.scaleBy(scale,
duration: scaleDuration))
ٿᐽతલޙҐஔ • ٿࡏ্ঋత࣌ީጯ֘ཁ֖ॅᐽɼԼ߱࣌ཁඃᐽ֖ॅ var appearBeforeRing:Bool { set { zPosition =
newValue ? 1 : -1 } get { return zPosition == 1 } }
Demo
Source Code https://gist.github.com/ bdf61305b74305079d3bae198b09 e0b2
Q&A