Swift4 Day87:Angry bird憤怒鳥2

Swift4 / iOS11 / 2018.03.25

Alice
Daily Swift
3 min readMar 25, 2018

--

寫Medium的意義在於,之後想做相同的東西時,能夠找到之前怎麼做的。

Angry Birds 8 — Moving the Bird物件跟著手指移動

Angry Birds 6 — Pinch to Zoom雙指縮放鏡頭

但用雙指縮放大小會超出圖片,所以要限制鏡頭。讓大小不要超出範圍。

但在let translation = sender.translation(in: view) * gameCamera.yScale時

會顯示:Binary operator ‘*’ cannot be applied to operands of type ‘CGPoint’ and ‘CGFloat’

寫一個Swift檔,用function讓CGPoint可以轉換成CGPoint

Angry Birds 7 — Bird Class加上鳥的物件

先用紅色方塊代替鳥

寫一個Bird.swift,建立Bird的物件

用addBird把Bird加到畫面上,再用anchor控制鳥的位置。

就會做出這樣的結果~

Angry Birds 8 — Moving the Bird物件跟著手指移動

在bird的class加上一個grabbed屬性

程式碼在這:按這裡

--

--