MAC_COCOS2D-X学习——Cocos2dx网格动作

    最近上课的作业就是研究cocos2dx,所以之后的大部分题目可能都会和cocos2dx有关,这一次来讲一讲cocos2dx的网格动作。就是这个样子的动作




    直接开始吧,首先是创建helloworld程序(我默认你们的环境都搭好了,是在mac上的),

    创建完之后编译运行一下,在mac上运行(不是ios模拟器),初次编译过程有点长,可以先去准备一下素材。

    这里我们将素材包拷贝到项目目录下的resources文件夹下



    编译好了后,看看效果


    我们改一改HelloworldScene.h如下

#include "cocos2d.h"

typedef enum//添加了存储各种动作标记的结构体
{
    kFlipX3D=100,
    kLens3D,
    kLiquid,
    kPageTurn3D,
    kRipple3D,
    kShaky3D,
    kTwirl,
    kWaves,
    kWave3D,
    kFadeOutTRTiles,
    kJumpTiles3D,
    kShakyTiles3D,
    kShatteredTiles3D,
    kShuffleTiles,
    kSplitCols
} ActionTypes;

class HelloWorld : public cocos2d::Scene
{
public:
    static cocos2d::Scene* createScene();

    virtual bool init();
    void OnclickMenu(cocos2d::Ref *pSender);//添加了菜单点击方法
    CREATE_FUNC(HelloWorld);
};
    修改helloworld.cpp如下
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"

USING_NS_CC;

Scene* HelloWorld::createScene()
{
    return HelloWorld::create();
}

static void problemLoading(const char* filename)
{
    printf("Error while loading: %s\n", filename);
    printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in HelloWorldScene.cpp\n");
}

bool HelloWorld::init()
{
    if ( !Scene::init() )
    {
        return false;
    }
    
    cocos2d::Size visibleSize = cocos2d::Director::getInstance()->getVisibleSize();
    cocos2d::Vec2 origin = cocos2d::Director::getInstance()->getVisibleOrigin();
    
    auto bg = cocos2d::Sprite::create("HelloWorld.png");
    if (bg == nullptr)
    {
        problemLoading("'HelloWorld.png'");
    }
    else
    {
        bg->setPosition(Vec2(origin.x+visibleSize.width/2,origin.y+visibleSize.height/2));
        this->addChild(bg);
    }
    
    auto FlipX3DLable = cocos2d::Label::createWithBMFont("fonts/fnt2.fnt", "FlipX3D");
    auto FlipX3DMenu = cocos2d::MenuItemLabel::create(FlipX3DLable, CC_CALLBACK_1(HelloWorld::OnclickMenu, this));
    FlipX3DMenu->setTag(kFlipX3D);
    
    auto kLens3Dlabel = cocos2d::Label::createWithBMFont("fonts/fnt2.fnt", "Lens3D");
    auto kLens3Dmenu = cocos2d::MenuItemLabel::create(kLens3Dlabel,
                                                      CC_CALLBACK_1(HelloWorld::OnclickMenu, this));
    kLens3Dmenu->setTag(kLens3D);
    
    auto Twirllabel = cocos2d::Label::createWithBMFont("fonts/fnt2.fnt", "Twirl");
    auto Twirlmenu = cocos2d::MenuItemLabel::create(Twirllabel,
                                                    CC_CALLBACK_1(HelloWorld::OnclickMenu, this));
    Twirlmenu->setTag(kTwirl);
    
    auto FadeOutTRTilesLabel = cocos2d::Label::createWithBMFont("fonts/fnt2.fnt", "FadeOutTRTiles");
    auto FadeOutTRTilesMenu = cocos2d::MenuItemLabel::create(FadeOutTRTilesLabel,
                                                             CC_CALLBACK_1(HelloWorld::OnclickMenu, this));;
    FadeOutTRTilesMenu->setTag(kFadeOutTRTiles);
    
    auto ShatteredTiles3DLabel = cocos2d::Label::createWithBMFont("fonts/fnt2.fnt", "ShatteredTiles3D");
    auto ShatteredTiles3DMenu = cocos2d::MenuItemLabel::create(ShatteredTiles3DLabel,
                                                               CC_CALLBACK_1(HelloWorld::OnclickMenu, this));
    ShatteredTiles3DMenu->setTag(kShatteredTiles3D);
    
    auto mn = cocos2d::Menu::create(FlipX3DMenu, kLens3Dmenu, Twirlmenu, FadeOutTRTilesMenu, ShatteredTiles3DMenu, NULL);
    mn->alignItemsVertically();
    mn->setPosition(Vec2(origin.x+visibleSize.width/4, origin.y+visibleSize.height/2));
    this->addChild(mn);
    
    
    
    
    auto kLiquidLable = cocos2d::Label::createWithBMFont("fonts/fnt2.fnt", "Liquid");
    auto kLiquidMenu = cocos2d::MenuItemLabel::create(kLiquidLable, CC_CALLBACK_1(HelloWorld::OnclickMenu, this));
    kLiquidMenu->setTag(kLi
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值