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

用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();

}

原文:http://blog.csdn.net/zlqqhs/article/details/19766211

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值