Cocos2d-x   发布时间:2022-05-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Cocos2d-x 3.8中怎么创建九宫格精灵大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

查了好久,今天才在官网论坛找到了方法,因为好像3.3之后就不是导一个现有项的那种方法了。闲话不多说,创建方法只需要两步

  1. #include “ui\UIScale9Sprite.h”
  2. 使用的时候这样写才能不出错
    auto nineGirl = ui::Scale9Sprite::create(“button.png”);

贴一个自己的非常简单的代码


#include "HelloWorldScene.h"
#include "ui\UIScale9Sprite.h"
using namespace cocos2d;

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();
    Vec2 origin = Director::geTinstance()->getVisibLeorigin();

    auto nineGirl = ui::Scale9Sprite::create("button.png");
    nineGirl->setContentSize(Size(200,200));
    nineGirl->setPosition(Vec2(200,200));
    this->addChild(nineGirl);
    return true;
}


void HelloWorld::menuCloseCallBACk(Ref* pSender)
{
    Director::geTinstance()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
}

再次感谢这两位仁兄,出处:官方论坛-3.4 中如何使用Scale9Sprite

大佬总结

以上是大佬教程为你收集整理的Cocos2d-x 3.8中怎么创建九宫格精灵全部内容,希望文章能够帮你解决Cocos2d-x 3.8中怎么创建九宫格精灵所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。