Cocos2d-x -- the rebound effect of the pop-up window of the national aircraft war

Source: Internet
Author: User

Use the HelloCpp project to modify the code:


#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();}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.