The Plane.
The Plane_mainMenu
2014-04-16
-----------------------------------------------------------------------------------------------------
三个文字Lable
创建成Menu后,第一个Label字体明显比第二个字体大,将CCMenuItemFont的setFont全去掉后,变成如图模样。
感觉很奇怪,原因思考中。
2014-04-17
-----------------------------------------------------------------------------------------------------
今天添加了按钮scene切换,点击Start跳转到游戏黑屏,Exit退出游戏。
2014-04-18
-----------------------------------------------------------------------------------------------------
团建。
2014-04-19
-----------------------------------------------------------------------------------------------------
团建。
2014-04-20
-----------------------------------------------------------------------------------------------------
今天准备好了画线,点,形。
2014-04-21
-----------------------------------------------------------------------------------------------------
今天添加了触摸事件,现在可以搬运着方框到处跑拉,当然,是无限制的。明天完善一下。
遇到问题:error C2061: 语法错误: 标识符“CCSet”
解决方法:在相应文件中添加引用宏“USING_NS_CC;”
实现以下三个方法:
virtual voidccTouchesBegan(CCSet* pTouches, CCEvent* event);virtual voidccTouchesMoved(CCSet* pTouches, CCEvent* event);virtual voidccTouchesEnded(CCSet* pTouches, CCEvent* event);在init方法中设置可触摸为true
this->setTouchEnabled(true);
拖动的动作主要是在moved中实现的。
2014-04-22
-----------------------------------------------------------------------------------------------------
今天头脑风暴,屏幕移动还没有实现完成,明天需要继续。最近几天头好乱,思绪是一点都没有拉。
以飞机为中心,四个方向
//up (down,left,right)
//down (up,left,right)
//left(up,down,right)
//right(up,down,left)
后来一想好像不对,触摸屏幕中的任意一点,不用来区分上下左右,还是直接计算触摸点和拖动点的距离差比较靠谱些。
2014-04-23
-----------------------------------------------------------------------------------------------------
今天终于明白之前的错误在哪里了,今天我重新写了GameObject类,继续了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();
实现方法如上,在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);
}
}
这样就可以实现随拖动坐标走动了,但现在有一个不好的地方,必须要触摸到Plane才会移动,可以考虑优化为触摸屏幕上任意一点,都随着移动,因为有些时候,你的手可能会挡到飞机拉,有那么复杂吗?哈哈,很简单拉,只需要把 if(!containsTouchLocation(touch)){
returnfalse;
}
去掉就OK拉,现在不必是必须触摸飞机本身喽,屏幕里的任意点都会生效。
隐形坑:
这里要注意的是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
-----------------------------------------------------------------------------------------------------
今天预想的是添加子弹,但遇到了一些问题,最后决定先添加一个激光枪吧,嘿嘿,因为它不涉及什么先后出现顺序问题,就一直在那就行拉。明天在继续想一下怎么实现圈圈子弹效果。
这些还都没有设置碰撞体,等先把子弹效果实现在来添加一下。
2014-05-03
-----------------------------------------------------------------------------------------------------
终于有时间来继续这个了,3.0了,好快。
《1》draw不能再被重写了,那么我们只能来用另外一个带好多参数的了,但调用方法和之前一样。
《2》touch需要注册下listen了,要不不会在触发。
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之屌丝体验点评