Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
用SpriteKit 做一個FB 投籃遊戲
Search
Johnlin
April 12, 2016
Programming
1
190
用SpriteKit 做一個FB 投籃遊戲
Johnlin
April 12, 2016
Tweet
Share
More Decks by Johnlin
See All by Johnlin
用 MLIR 實作 一個 Ruby IR (intermediate representation)
johnlinvc
0
49
Unearth Ruby builtin Gems 發掘 Ruby 的內建 Gems
johnlinvc
0
200
Ruby 型別檢查工具簡介
johnlinvc
0
400
Swift Actor 實作探索
johnlinvc
0
130
用 mruby 來寫跨平台工具
johnlinvc
0
56
Actor model 簡介
johnlinvc
0
160
一起玩 Helm 3
johnlinvc
1
100
為什麼 App 卡卡的
johnlinvc
2
1.1k
如何使用 byebug 來除錯 Ruby 程式
johnlinvc
0
160
Other Decks in Programming
See All in Programming
CSC509 Lecture 11
javiergs
PRO
0
180
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
690
Contemporary Test Cases
maaretp
0
140
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
イベント駆動で成長して委員会
happymana
1
320
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
120
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
170
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
Remix on Hono on Cloudflare Workers
yusukebe
1
290
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
50
7.2k
The Cult of Friendly URLs
andyhume
78
6k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Designing Experiences People Love
moore
138
23k
Adopting Sorbet at Scale
ufuk
73
9.1k
Writing Fast Ruby
sferik
627
61k
Designing for humans not robots
tammielis
250
25k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Making Projects Easy
brettharned
115
5.9k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
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