Swift 2 中的遊戲 - “touchesBegan”? (Game in Swift 2 - "touchesBegan"?)


問題描述

Swift 2 中的遊戲 ‑ “touchesBegan”? (Game in Swift 2 ‑ "touchesBegan"?)

我想構建一個遊戲,當我觸摸和拖動時,它會在觸摸的位置創建一條與拖動方向相同的線,並在遊戲的邊界處結束(在本例中是我的框架)。

關於如何解決這個問題的任何提示?


參考解法

方法 1:

Your search term in UIPanGestureRecognizer.

You'd create a pan gesture recognizer and attach it to your view. In the method that it calls, look for the state UIGestureRecognizerStateBegan. Record the start position, then respond to calls to your action method with the state UIGestureRecognizerStateChanged.

That should be enough to get you started. As Matt says, this is a fairly common use case, so you should be able to find sample code online if you can't work this out from the docs.

(by YansinDuncan C)

參考文件

  1. Game in Swift 2 ‑ "touchesBegan"? (CC BY‑SA 2.5/3.0/4.0)

#game-physics #iOS #swift2 #swift






相關問題

Android AndEngine:簡單的精靈碰撞 (Android AndEngine: Simple sprite collision)

Box2D - 收集硬幣 (Box2D - collect a coin)

LibGDX - 只有可拖動的運動 (LibGDX - only draggable movement)

Swift 2 中的遊戲 - “touchesBegan”? (Game in Swift 2 - "touchesBegan"?)

SKCameraNode 跟不上移動節點 (SKCameraNode doesn't keep up with moving node)

2D 平台遊戲:為什麼讓物理依賴於幀率? (2D platformers: why make the physics dependent on the framerate?)

基於脈衝的物理 - 在輕物體上堆疊重物體 (Impulse based physics - Stacking heavy object on light object)

建造一堵提高速度統一的牆 (Make a wall that boost speed unity)

Unity Golf 遊戲物理和運動控制器 (Unity Golf game physics and movement controller)

在 2D 汽車遊戲中模擬下壓力 (Simulate Downforce in a 2D Car Game)

向前和橫向球員運動 (Forward and Sideways Player movement)

如何在 Unity 中進行沒有物理的碰撞檢測? (How to have collision detection without physics in Unity?)







留言討論