Cocos2d-x 3.8中怎么创建九宫格精灵

Cocos2d-x 3.8中怎么创建九宫格精灵,第1张

概述查了好久,今天才在官网论坛找到了方法,因为好像3.3之后就不是导一个现有项的那种方法了。闲话不多说,创建方法只需要两步 #include “ui\UIScale9Sprite.h” 使用的时候这样写才能不出错 auto nineGirl = ui::Scale9Sprite::create(“button.png”); 贴一个自己的非常简单的代码 #include "HelloWorldScene

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

#include “ui\UIScale9Sprite.h” 使用的时候这样写才能不出错
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 instancebool 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中怎么创建九宫格精灵所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1072607.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存