拉伸菜单与返回菜单

前端之家收集整理的这篇文章主要介绍了拉伸菜单与返回菜单前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

//前言: 希望我的博客能帮助到那些出入cocos2d-x的小伙伴们,我的也刚刚入职没多久差不多一年快一年了,我希望新手小伙伴们不要一味的去抄袭别人的博客,你要带着思考去理解别人为什么要这样写,这样写的作用是什么,有什么不足或者有哪些优点。

废话不多说开始撸码;

ifndef SWALLOWTOUCH_H

define SWALLOWTOUCH_H

include “cocos2d.h”

include “HelloWorldScene.h”

include “cocostudio/CocoStudio.h”

include “ui/CocosGUI.h”

include “swallowTouch.h”

include

class swallowTouch : public Layer { public: swallowTouch(); ~swallowTouch(); static Scene* crectscene(); virtual bool init(); void MoveMenu(Ref *obj); Sprite* sprite_image; bool _isScale; void Hore_Menu(Ref *obj); void Hore_Menu2(Ref *obj); //Hoer footer_soul strongthen team settings_icon CC_SYNTHESIZE(ui::Button*,m_pButton,Button); //footer_soul CC_SYNTHESIZE(ui::Button*,m_pFooter_soulButton,Footer_soulButton); //Strongthen; CC_SYNTHESIZE(ui::Button*,m_pStrongthenButton,StrongthenButton); //Team CC_SYNTHESIZE(ui::Button*,m_pTeamButton,TeamButton); //Settings_icon CC_SYNTHESIZE(ui::Button*,m_pSettings_iconButton,Settings_iconButton); CREATE_FUNC(swallowTouch); }; #endif // !__SWALLOWTOUCH_H__

CPP

#include "swallowTouch.h"


swallowTouch::swallowTouch() :_isScale(false),m_pButton(nullptr),m_pFooter_soulButton(nullptr),m_pSettings_iconButton(nullptr),m_pStrongthenButton(nullptr),m_pTeamButton(nullptr)
{
}


swallowTouch::~swallowTouch()
{
}

bool swallowTouch::init()
{
    if (!Layer::init())
    {
        return false;
    }

    Size size = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    sprite_image = Sprite::create("cbattle_page_name_bg.png");
    sprite_image->setPosition(Vec2(size.width / 2 + 703,size.height / 2 - 320));
    //sprite_image->setTag(10);
    this->addChild(sprite_image);
    /*MoveMenu(Ref *obj);*/

    auto hero_button = MenuItemImage::create("footer_menu_close.png","footer_menu_close1.png",CC_CALLBACK_1(swallowTouch::MoveMenu,this));
    hero_button->setPosition(Vec2(size.width / 2 + 470,size.height / 2 - 320));
    auto menu = Menu::create(hero_button,NULL);
    menu->setPosition(Vec2::ZERO);
    this->addChild(menu,1);

    //Hore Button;
    m_pButton = Button::create("footer_menu_hero.png","slowleaf.png");
    getButton()->setAnchorPoint(ccp(0,0));
    getButton()->setPosition(ccp(0,0));
    sprite_image->addChild(getButton());
    ScaleTo* slto1 = ScaleTo::create(0.0f,0.35f,0.35f);
    m_pButton->runAction(slto1);

    //footer_soul Button;
    m_pFooter_soulButton = Button::create("footer_menu_soul.png","slowleaf2.png");
    getFooter_soulButton()->setAnchorPoint(ccp(0,0));
    getFooter_soulButton()->setPosition(ccp(35,0));
    sprite_image->addChild(getFooter_soulButton());
    ScaleTo* slto2 = ScaleTo::create(0.0f,0.35f);
    m_pFooter_soulButton->runAction(slto2);

    //strongthen Button;
    m_pSettings_iconButton = Button::create("footer_menu_strongthen.png","slowleaf3.png");
    getSettings_iconButton()->setAnchorPoint(ccp(0,0));
    getSettings_iconButton()->setPosition(ccp(70,0));
    sprite_image->addChild(getSettings_iconButton());
    ScaleTo* slto3 = ScaleTo::create(0.0f,0.35f);
    m_pSettings_iconButton->runAction(slto3);

    //team Button;
    m_pStrongthenButton = Button::create("footer_menu_team.png","slowleaf4.png");
    getStrongthenButton()->setAnchorPoint(ccp(0,0));
    getStrongthenButton()->setPosition(ccp(105,0));
    sprite_image->addChild(getStrongthenButton());
    ScaleTo* slto4 = ScaleTo::create(0.0f,0.35f);
    m_pStrongthenButton->runAction(slto4);

    //settings_icon Button;
    m_pTeamButton = Button::create("settings_icon.png","slowleaf5.png");
    getTeamButton()->setAnchorPoint(ccp(0,0));
    getTeamButton()->setPosition(ccp(140,0));
    sprite_image->addChild(getTeamButton());
    ScaleTo* slto5 = ScaleTo::create(0.0f,0.6f,0.6f);
    m_pTeamButton->runAction(slto5);

/*
    auto hero_button4 = MenuItemImage::create("footer_menu_strongthen.png","footer_menu_close3.png",this));
    hero_button4->setPosition(Vec2(size.width / 2,size.height / 2));
    auto menu4 = Menu::create(hero_button4,NULL);
    menu4->setPosition(Vec2::ZERO);
    this->addChild(menu4,1);*/

    return true;
}


Scene* swallowTouch::crectscene()
{
    auto scene = Scene::create();

    auto layer = swallowTouch::create();

    scene->addChild(layer);


    return scene;
}


void swallowTouch::MoveMenu(Ref *obj)
{

    Size size = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    ScaleTo* slto = ScaleTo::create(0.0f,2.0f,2.0f);
    sprite_image->runAction(slto);

    MoveTo* c_moveby;
    if (_isScale)
    {
        //缩
        c_moveby = MoveTo::create(0,Vec2(size.width / 2 + 703,size.height / 2 - 320));
        sprite_image->runAction(c_moveby);
        _isScale = false;
    }
    else
    {
        //伸
        c_moveby = MoveTo::create(0,Vec2(size.width / 2 + 270,size.height / 2 - 320));
        sprite_image->runAction(c_moveby);
        _isScale = true;
    }
    //移动;


    Sequence* pSequence = Sequence::create(slto,c_moveby,NULL);
}

void swallowTouch::Hore_Menu(Ref *obj)
{
    log("hore hore");

    //MoveMenu();
}

void swallowTouch::Hore_Menu2(Ref *obj)
{
    log("--------");
}
原文链接:https://www.f2er.com/cocos2dx/343851.html

猜你在找的Cocos2d-x相关文章