//字符串:
//初始化
CCLabelTTF* pLabel=CCLabelTTF::create("Hello Cocos2d-x","Arial",24);
//检测
CC_BREAK_IF(!pLabel);
//设置坐标
CCSize size=CCDirector::sharedDirector()->getWinSize();
pLabel->setPosition(ccp(size.width/2,size.height-50));
//加入图层
this->addChild(pLabel,1);
//图片
//初始化
CCSprite* pSprite=CCSprite::create("HelloWorld.png");
//检测
CC_BREAK_IF(!pSprite);
//设置坐标
CCSize size1=CCDirector::sharedDirector()->getWinSize();
pSprite->setPosition(ccp(size1.width/2,size1.height/2));
//加入图层
this->addChild(pSprite,1);
//文本按钮1
//初始化
CCLabelTTF* pBtn=CCLabelTTF::create("Button","Arial",24);
//检测
CC_BREAK_IF(!pBtn);
//设置坐标+生成
CCMenuItemLabel* pltemLabel=CCMenuItemLabel::create(pBtn);
CC_BREAK_IF(!pltemLabel);
pltemLabel->setPosition(ccp(100,100));
//添加到Menu层
CCMenu* pMenu=CCMenu::create(pltemLabel,NULL);
CC_BREAK_IF(!pMenu);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu,1);
//文本按钮2
//初始化
CCMenuItemFont* pltemFont=CCMenuItemFont::create("pBtn",this,NULL);
CC_BREAK_IF(!pltemFont);
pltemFont->setPosition(ccp(300,300));
//添加到Menu层
CCMenu* pMenu1=CCMenu::create(pltemFont,NULL);
CC_BREAK_IF(!pMenu1);
pMenu1->setPosition(CCPointZero);
this->addChild(pMenu1,1);
//图片按钮
CCMenuItemImage* pItemImage=CCMenuItemImage::create("CloseNormal.png","CloseSelected.png",this,NULL);
CC_BREAK_IF(!pItemImage);
pItemImage->setPosition(ccp(100,200));
CCMenu* pMenu2=CCMenu::create(pItemImage,NULL);
CC_BREAK_IF(!pMenu2);
pMenu2->setPosition(CCPointZero);
this->addChild(pMenu2,1);
//动画
CCTexture2D* pTexture=CCTextureCache::sharedTextureCache()->addImage("pic473.png");
CCSpriteFrame *frame0=CCSpriteFrame::createWithTexture(pTexture,CCRectMake(64*0,128*0,64,128));
CCSpriteFrame *frame1=CCSpriteFrame::createWithTexture(pTexture,CCRectMake(64*1,128*0,64,128));
CCSpriteFrame *frame2=CCSpriteFrame::createWithTexture(pTexture,CCRectMake(64*2,128*0,64,128));
CCSpriteFrame *frame3=CCSpriteFrame::createWithTexture(pTexture,CCRectMake(64*3,128*0,64,128));
CCArray* pArray=CCArray::createWithCapacity(4);
pArray->addObject(frame0);
pArray->addObject(frame1);
pArray->addObject(frame2);
pArray->addObject(frame3);
CCAnimation* animation=CCAnimation::createWithSpriteFrames(pArray,0.3f);
CCSprite* ss=CCSprite::createWithSpriteFrame(frame0);
ss->setPosition(ccp(200,200));
this->addChild(ss,1);
CCAnimate* aa=CCAnimate::create(animation);
ss->runAction(CCRepeatForever::create(aa));
//getContentSize()为CCSprite精灵锚点就是图片的大小
//实现监控 每一秒执行一次HelloWorld::gameLogic()函数一次
this->schedule( schedule_selector(HelloWorld::gameLogic), 1.0 );
// CCFiniteTimeAction* 延时动作CCMoveTo::create(time,ccp(point))
CCSprite* sprite = (CCSprite*)this->getChildByTag(0);
//创建动作
CCPlace* action1 = CCPlace::create(ccp(100,100));
CCFlipX* action2 = CCFlipX::create(true);
CCMoveTo* moveTo = CCMoveTo::create(2.0f, ccp(100,0));
CCMoveBy* moveBy = CCMoveBy::create(4.0f, ccp(200,0));
CCRotateTo* rotateTo = CCRotateTo::create(2.0f, 360);
CCRotateBy* rotateBy = CCRotateBy::create(2.0f, 720);
//创建重复动作,重复执行rotateBy动作四次
CCRepeat* repeat = CCRepeat::create(rotateBy, 4);
//重复执行rotateBy动作
CCRepeatForever* repeatForever = CCRepeatForever::create(rotateBy);
CCJumpBy* jumpBy = CCJumpBy::create(3.0f, ccp(200,0), 40, 2);
//执行jumpBy的反动作,所有以By为结尾的动作,都可以用reverse()方法获取他的反动作
CCActionInterval* jumpBack = jumpBy->reverse();
//同步动作序列,多个动作可以一起执行,同步队列单次执行时间以动作序列中执行时间最长的确定
CCFiniteTimeAction* spawn = CCSpawn::create(moveBy, rotateBy, NULL);
//同步序列中两个动作执行时间不同,创建重复执行动作,可以查看运行时间
CCRepeat* re = CCRepeat::create(spawn, 2);
//变速动作,通过schedule改变speed的速率,达到改变动作快慢的功能
CCSpeed* speed = CCSpeed::create(re, 1.0f);
speed->setTag(1);
sprite->runAction(speed);
this->schedule(schedule_selector(HelloWorld::go), 0.5f);
//跟随动作,可以让一个节点跟随另一节点运动,一般用于层跟随节点运动,达到镜头跟随的效果
CCFollow* follow = CCFollow::create(sprite);
this->runAction(follow);
cocos2d-x 笔记小记2
最新推荐文章于 2023-03-25 12:26:39 发布