資料來源: 千鋒獨家出品《Android遊戲開發基礎視頻教程》http://www.mobiletrain.org/about/news/android_video3.html
* 什麼是向量
* 基于向量的計算
** 向量的加減法
CGPoint deltaPoint = CGPoint.ccp(0, 200);
CGPoint targetPoint = CGPoint.ccpAdd(cgPoint, deltaPoint);
CGPoint subPoint = CGPoint.ccp(200, 300);
CGPoint tgPoint = CGPoint.ccpSub(targetPoint, subPoint);
** 向量的乘除法
CGPoint newPoint = CGPoint.ccpMult(tgPoint, 2);
** 計算單位向量
* 使用 CGPoint 對象代表向量
CGPoint anotherPoint = CGPoint.ccpNormalize(tgPoint);
* 基于向量的運算
* CCMoveBy 與 CCJumpBy
CGPoint onePoint = CGPoint.ccp(500, 300);
CCMoveBy moveBy = CCMoveBy.action(5, onePoint);
CGPoint jumpPoint = CGPoint.ccp(300, 100);
CCJumpBy jumpBy = CCJumpBy.action(5, deltaPoint, 500, 5);
* 總結
No comments:
Post a Comment