The Plane.
The Plane_mainMenu
2014-04-16
-----------------------------------------------------------------------------------------------------
三個文字Lable
創(chuàng)建成Menu后,第一個Label字體明顯比第二個字體大,將CCMenuItemFont的setFont全去掉后,變成如圖模樣。
感覺很奇怪,原因思考中。
2014-04-17
-----------------------------------------------------------------------------------------------------
今天添加了按鈕scene切換,點擊Start跳轉到游戲黑屏,Exit退出游戲。
2014-04-18
-----------------------------------------------------------------------------------------------------
團建。
2014-04-19
-----------------------------------------------------------------------------------------------------
團建。
2014-04-20
-----------------------------------------------------------------------------------------------------
今天準備好了畫線,點,形。
2014-04-21
-----------------------------------------------------------------------------------------------------
今天添加了觸摸事件,現(xiàn)在可以搬運著方框到處跑拉,當然,是無限制的。明天完善一下。
遇到問題:error C2061: 語法錯誤: 標識符“CCSet”
解決方法:在相應文件中添加引用宏“USING_NS_CC;”
?
實現(xiàn)以下三個方法:
virtual voidccTouchesBegan(CCSet* pTouches, CCEvent* event);virtual voidccTouchesMoved(CCSet* pTouches, CCEvent* event);virtual voidccTouchesEnded(CCSet* pTouches, CCEvent* event);在init方法中設置可觸摸為true
?this->setTouchEnabled(true);
?
拖動的動作主要是在moved中實現(xiàn)的。
2014-04-22
-----------------------------------------------------------------------------------------------------
今天頭腦風暴,屏幕移動還沒有實現(xiàn)完成,明天需要繼續(xù)。最近幾天頭好亂,思緒是一點都沒有拉。
以飛機為中心,四個方向
//up ? (down,left,right)
//down (up,left,right)
//left(up,down,right)
//right(up,down,left)
后來一想好像不對,觸摸屏幕中的任意一點,不用來區(qū)分上下左右,還是直接計算觸摸點和拖動點的距離差比較靠譜些。
2014-04-23
-----------------------------------------------------------------------------------------------------
?
今天終于明白之前的錯誤在哪里了,今天我重新寫了GameObject類,繼續(xù)了CCNode,和CCTargetedTouchDelegate。
?????? virtualvoid onEnter();
?????? virtualvoid onExit();
?????? boolcontainsTouchLocation(CCTouch* touch);
?????? virtualbool ccTouchBegan(CCTouch* touch, CCEvent* event);
?????? virtualvoid ccTouchMoved(CCTouch* touch, CCEvent* event);
?????? virtualvoid ccTouchEnded(CCTouch* touch, CCEvent* event);
?
?????? virtualvoid touchDelegateRetain();
?????? virtualvoid touchDelegateRelease();
?
實現(xiàn)方法如上,在OnEnter()中添加觸摸響應。
?
偏移計算方法為
?
bool GameObject::ccTouchBegan(CCTouch*touch, CCEvent* event){
?????? if(!containsTouchLocation(touch)){
????????????? returnfalse;
?????? }
?????? else{
????????????? iscontrol= true;
????????????? CCPointtap = touch->getLocationInView();
????????????? tap= CCDirector::sharedDirector()->convertToGL(tap);
????????????? offset.x= tap.x - this->getPosition().x;
????????????? offset.y= tap.y - this->getPosition().y;
?????? }
?????? returntrue;
}
?
void GameObject::ccTouchMoved(CCTouch*touch, CCEvent* event){
?????? if(iscontrol){
????????????? CCPointtap = touch->getLocationInView();
????????????? tap= CCDirector::sharedDirector()->convertToGL(tap);
?
????????????? floatx = tap.x - offset.x;
????????????? floaty = tap.y - offset.y;
????????????? //setPosition(ccp(tap.x,getPosition().y));
????????????? this->setPosition(x,y);
?????? }
}
?
這樣就可以實現(xiàn)隨拖動坐標走動了,但現(xiàn)在有一個不好的地方,必須要觸摸到Plane才會移動,可以考慮優(yōu)化為觸摸屏幕上任意一點,都隨著移動,因為有些時候,你的手可能會擋到飛機拉,有那么復雜嗎?哈哈,很簡單拉,只需要把??? if(!containsTouchLocation(touch)){
????????????? returnfalse;
?????? }
去掉就OK拉,現(xiàn)在不必是必須觸摸飛機本身嘍,屏幕里的任意點都會生效。
?
?
隱形坑:
?
這里要注意的是getLocation()和getLocationInView(),前者在這種移動方法中,可能會造成Y軸反方向,所以需要使用在視圖內的Location.
???/** returns the current touch location in screen coordinates */
CCPoint getLocationInView() const;
?
???/** returns the current touch location in OpenGL coordinates */
CCPoint getLocation() const;
?
看到了吧,getLocation是返回在OpenGl中的坐標,面OpenGl的坐標系好像正好和實際相反。
2014-04-24
-----------------------------------------------------------------------------------------------------
?
今天預想的是添加子彈,但遇到了一些問題,最后決定先添加一個激光槍吧,嘿嘿,因為它不涉及什么先后出現(xiàn)順序問題,就一直在那就行拉。明天在繼續(xù)想一下怎么實現(xiàn)圈圈子彈效果。
這些還都沒有設置碰撞體,等先把子彈效果實現(xiàn)在來添加一下。
2014-05-03
-----------------------------------------------------------------------------------------------------
終于有時間來繼續(xù)這個了,3.0了,好快。
《1》draw不能再被重寫了,那么我們只能來用另外一個帶好多參數(shù)的了,但調用方法和之前一樣。
《2》touch需要注冊下listen了,要不不會在觸發(fā)。
Node::onEnter();// Register Touch Eventauto listener = EventListenerTouchOneByOne::create();listener->setSwallowTouches(true);listener->onTouchBegan = CC_CALLBACK_2(Player::onTouchBegan, this);listener->onTouchMoved = CC_CALLBACK_2(Player::onTouchMoved, this);listener->onTouchEnded = CC_CALLBACK_2(Player::onTouchEnded, this);_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);《3》undefined reference to? XXX 遇到這個一般是沒有找到引用 ,尋思了半天,最后終于想起,我用的make編輯器不會自動 把你新添加的代碼文件放到make列表的,自己手動加一下吧。。。。。。想了半天才想到,好2 -+-。
總結
以上是生活随笔為你收集整理的The Plane.的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 辅助驾驶功能开发-功能对标篇(18)-N
- 下一篇: 微软IE10之屌丝体验点评