您的位置:首页 > 移动开发 > Cocos引擎

Cocos2d-x--全民飞机大战弹窗回弹效果

2014-02-23 19:52 375 查看
用HelloCpp工程修改代码:

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"

class HelloWorld : public cocos2d::CCLayer
{
public:
virtual bool init();

static cocos2d::CCScene* scene();
CREATE_FUNC(HelloWorld);

private:
void createWindow();
void destoryWindow(CCObject* pSender);
void popWindow(CCObject* pSender);
};

#endif


#include "HelloWorldScene.h"
#include "AppMacros.h"
USING_NS_CC;

CCScene* HelloWorld::scene()
{
CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}

bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}

CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

CCMenuItemImage *pPopWindowItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::popWindow));

pPopWindowItem->setPosition(ccp(origin.x + visibleSize.width - pPopWindowItem->getContentSize().width/2 ,
origin.y + pPopWindowItem->getContentSize().height/2));

CCMenu* pPopWindowMenu = CCMenu::create(pPopWindowItem, NULL);
pPopWindowMenu->setPosition(CCPointZero);
this->addChild(pPopWindowMenu, 1);

CCMenuItemImage *pDestoryWindowItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::destoryWindow));
pDestoryWindowItem->setPosition(ccp(50.0f, 50.0f));
CCMenu* pDestoryWindowMenu = CCMenu::create(pDestoryWindowItem, NULL);
pDestoryWindowMenu->setPosition(CCPointZero);
this->addChild(pDestoryWindowMenu, 1);

return true;
}

void HelloWorld::popWindow(CCObject* pSender)
{
createWindow();
}

void HelloWorld::createWindow()
{
CCSprite* pWindow = CCSprite::create("HelloWorld.png");
pWindow->setScale(0.2f);
pWindow->setPosition(ccp(240.0f, 140.0f));
pWindow->setTag(10);
this->addChild(pWindow);
CCScaleTo *pScaleTo = CCScaleTo::create(1.0f, 0.7f, 0.7f);
CCActionInterval *pAction = CCEaseElasticOut ::create(pScaleTo);
pWindow->runAction(pAction);
}

void HelloWorld::destoryWindow( CCObject* pSender )
{
this->getChildByTag(10)->removeFromParent();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息