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();
}
#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();
}
相关文章推荐
- ActionScript 3.0 编程体验
- 突破winxp sp2/win2003 sp2超强弹窗代码
- ASP.NET MVC:Filter和Action的执行介绍
- Ajax in action 英文版配书源码 下载
- ajax交互Struts2的action(客户端/服务器端)
- js点击弹出div层实现可拖曳的弹窗效果
- js解决弹窗问题实现班级跳转DIV示例
- android教程之intent的action属性使用示例(intent发短信)
- repeater做删除前弹窗询问实例
- 在页面上用action传递参数到后台出现乱码的解决方法
- 【cocos2d-x 手机游戏开发】Cocos2d-x 2.0 渲染到纹理深入分析
- 开放授权OpenPLM学习教程-文档管理
- 开放授权OpenPLM学习教程-项目管理
- 开放授权OpenPLM学习教程-物料管理
- 开放授权OpenPLM学习教程-变更管理
- 开放授权OpenPLM学习教程-问题管理
- 开放授权OpenPLM学习教程-制程管理
- Cocos2d-x 2.2+python开发环境配置和项目创建
- struts2 Action 访问Servlet API