cocos2d 人物移动
#include "HelloWorldScene.h" #include "MyLayer.h" using namespace cocos2d; CCScene* HelloWorld::scene() { CCScene * scene = NULL; do { // ‘scene‘ is an autorelease object scene = CCScene::create(); CC_BREAK_IF(! scene); // ‘layer‘ is an autorelease object HelloWorld *layer = HelloWorld::create(); CC_BREAK_IF(! layer); // add layer as a child to scene scene->addChild(layer); } while (0); // return the scene return scene; } // on "init" you need to initialize your instance bool HelloWorld::init() { bool bRet = false; do { ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// CC_BREAK_IF(! CCLayer::init()); //得到屏幕的大小 CCSize isize = CCDirector::sharedDirector()->getVisibleSize(); //建立一个精灵 CCSprite *pSprite = CCSprite::create("grossinis_sister1.png"); //设置精灵的起始位置 pSprite->setPosition(ccp(50,isize.height / 2)); //在层中添加精灵 this->addChild(pSprite); //定义移动方法 CCMoveTo *moveto = CCMoveTo::create(5,ccp(250,150)); //精灵执行移动方法 pSprite->runAction(moveto); // this->addChild(nineGile); bRet = true; } while (0); return bRet; } void HelloWorld::touchDown(CCObject*pObject,CCControlEvent event) { CCLOG("Touch Down"); } void HelloWorld::menuCloseCallback(CCObject* pSender) { // "close" menu item clicked // CCDirector::sharedDirector()->end(); CCDirector::sharedDirector()->replaceScene(CCTransitionSlideInT::create(3.0,CMyLayer::scence())); }
本文出自 “风清扬song” 博客,请务必保留此出处http://2309998.blog.51cto.com/2299998/1421042
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。