zoukankan      html  css  js  c++  java
  • 九阴白骨爪

    .cpp文件

    #include "HelloWorldScene.h"
    
    USING_NS_CC;
    
    Scene* HelloWorld::createScene()
    {
        // 'scene' is an autorelease object
        auto scene = Scene::create();
        
        // 'layer' is an autorelease object
        auto layer = HelloWorld::create();
    
        // add layer as a child to scene
        scene->addChild(layer);
    
        // return the scene
        return scene;
    }
    
    // on "init" you need to initialize your instance
    bool HelloWorld::init()
    {
        //////////////////////////////
        // 1. super init first
        if ( !Layer::init() )
        {
            return false;
        }
        
        Size visibleSize = Director::getInstance()->getVisibleSize();
        Point origin = Director::getInstance()->getVisibleOrigin();
    
    	SpriteFrameCache * cache = SpriteFrameCache::getInstance();
    	cache->addSpriteFramesWithFile("jiuyinbaiguzhua.plist","jiuyinbaiguzhua.png");
        
    	auto m_pSprite1 = Sprite::createWithSpriteFrameName("jiuyinbaiguzhua_1.png");
    	m_pSprite1->setPosition(visibleSize.width/2.0f,visibleSize.height/2.0f);
        addChild(m_pSprite1);
    
    	Vector<SpriteFrame*> animFrames(18);
    
        char str[100] = {0};
    
        for(int i = 1; i <= 18; i++) 
        {
            sprintf(str, "jiuyinbaiguzhua_%d.png", i);
            SpriteFrame* frame = cache->getSpriteFrameByName( str );
    		animFrames.pushBack(frame);
        }
    
    
    	Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
        m_pSprite1->runAction( RepeatForever::create( Animate::create(animation) ) );
    
        return true;
    }
    
    
    void HelloWorld::menuCloseCallback(Ref* pSender)
    {
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
    	MessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
        return;
    #endif
    
        Director::getInstance()->end();
    
    #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
        exit(0);
    #endif
    }
    

    .h文件

    #ifndef __HELLOWORLD_SCENE_H__
    #define __HELLOWORLD_SCENE_H__
    
    #include "cocos2d.h"
    
    class HelloWorld : public cocos2d::Layer
    {
    public:
        // there's no 'id' in cpp, so we recommend returning the class instance pointer
        static cocos2d::Scene* createScene();
    
        // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
        virtual bool init();  
        
        // a selector callback
        void menuCloseCallback(cocos2d::Ref* pSender);
        
        // implement the "static create()" method manually
        CREATE_FUNC(HelloWorld);
    };
    
    #endif // __HELLOWORLD_SCENE_H__
    

    效果图

  • 相关阅读:
    使用putty上传文件到linux系统
    常用网页背景颜色
    如果你在Windows下用putty来远程连接Linux发现乱码请用下面的方法解决:
    如何让plsql查询的数据可编辑
    oracle中not in(null)问题
    linux学习之路第三天(vim和vi使用)
    linux菜鸡学习之路
    常用正则表达式()
    JAVA WEB 用servlet实现分页,思路比较清晰和简单。
    linux学习之路第三天
  • 原文地址:https://www.cnblogs.com/Anzhongliu/p/6091876.html
Copyright © 2011-2022 走看看