一、TestCpp实例ActionsTest 模块中ActionManual动作
素材原图:
动作效果图:
程序代码:
bool HelloWorld::init() { if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); 设置猛兽白虎的x,y轴缩放、透明度 CCSprite *sp1 = CCSprite::create("cpp1.png"); sp1->setScale(1.0f); sp1->setScaleX(1.0f); sp1->setScaleY(-0.5f); sp1->setPosition(ccp(200,visibleSize.height/2)); sp1->setOpacity(150);//透明度 this->addChild(sp1); 设置天使MM的旋转、自身为红色 CCSprite *sp2 = CCSprite::create("cpp2.png"); sp2->setScale(0.5f); sp2->setRotation(300);//旋转0~360 sp2->setColor(ccc3(255,0,0)); sp2->setPosition(ccp(visibleSize.width/2, visibleSize.height/2)); this->addChild(sp2); 设置猛兽灰狼的颜色为蓝色 CCSprite *sp3 = CCSprite::create("cpp3.png"); sp3->setScale(0.5f); sp3->setColor( ccBLUE);//(0,0,255) sp3->setPosition(ccp(visibleSize.width-200, visibleSize.height/2)); this->addChild(sp3); return true; }
【Cocos2d TestCpp实例模仿】-- ActionsTest
时间: 2024-10-18 06:31:38