■環境
- cocos2d-x 2.1.5
- iOS6.0.1(iPod touch 5G)
- AppController.mmに以下を追加。
__glView.multipleTouchEnabled = true; // __glView定義直後でOK
- CCLayer派生クラスで以下のメソッドを定義
virtual void ccTouchesBegan(cocos2d::CCSet *touches, cocos2d::CCEvent *event);
virtual void ccTouchesMoved(cocos2d::CCSet *touches, cocos2d::CCEvent *event);
virtual void ccTouchesEnded(cocos2d::CCSet *touches, cocos2d::CCEvent *event);
- CCLayer派生クラスのinitに以下の処理を追加
setTouchEnabled(true);
setTouchMode(kCCTouchesAllAtOnce);
- CCLayer派生クラスに定義したメソッドを実装
// 実装の一例
/*!
* @brief タッチ開始デリゲート
* @param [in] touches ある瞬間にタッチされた情報(allTouchesではない)
* @param [in] event 未使用
*/
void MyLayer::ccTouchesBegan(CCSet *touches, CCEvent *event)
{
CC_UNUSED_PARAM(event);
for (CCSetIterator it = touches->begin(); it != touches->end(); ++it)
{
CCTouch *touch = (CCTouch *)(*it);
int id = touch->getID(); // 0 to (CC_MAX_TOUCHES - 1)
m_touchFlag[id] = true; // タッチ状態に遷移
m_touchAt [id] = touch->getLocation(); // 位置を保存
// 以下、必要な情報を取得し、update内で処理してやると良い
}
}
/*!
* @brief タッチ移動デリゲート
* @param [in] touches ある瞬間に移動した情報
* @param [in] event 未使用
*/
void MyLayer::ccTouchesMoved(CCSet *touches, CCEvent *event)
{
CC_UNUSED_PARAM(event);
for (CCSetIterator it = touches->begin(); it != touches->end(); ++it)
{
CCTouch *touch = (CCTouch *)(*it);
int id = touch->getID(); // 0 to (CC_MAX_TOUCHES - 1)
m_touchAt[id] = touch->getLocation(); // 位置を更新
m_delta[id] = touch->getDelta(); // 移動値を取得
// 以下、必要な情報を取得し、update内で処理してやると良い
}
}
/*!
* @brief タッチ終了デリゲート
* @param [in] touches ある瞬間に離された情報
* @param [in] event 未使用
*/
void MyLayer::ccTouchesEnded(CCSet *touches, CCEvent *event)
{
CC_UNUSED_PARAM(event);
for (CCSetIterator it = touches->begin(); it != touches->end(); ++it)
{
CCTouch *touch = (CCTouch *)(*it);
int id = touch->getID(); // 0 to (CC_MAX_TOUCHES - 1)
m_touchFlag[id] = false; // タッチ状態を終了
// 以下、必要があれば情報を初期化する
}
}
- ビルドして動作確認
- あとは実装次第
0 件のコメント:
コメントを投稿