Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 88737

动态加载spriteFrame需重新设置node的size

$
0
0

@745872343 写道:

如题,用代码创建节点,设置节点size后给其添加sprite组件,并设置spriteFrame,之后节点size会变为spriteFrame的原始size,需要重新设置。求问大神有没有办法解决这个问题

var courseMainNode = new cc.Node('mainNode'); //课件根节点

courseMainNode.parent = parentNode;

courseMainNode.width = parentNode.width;
courseMainNode.height = parentNode.height;

cc.loader.load('/Users/yamato/Documents/package/course_bg.png', function (err, tex) {
    if (err) {
            cc.error('load img error:' + err);
            return;
    } else {
            cc.log('load img success');

            var sp = courseMainNode.addComponent(cc.Sprite);

            sp.spriteFrame = new cc.SpriteFrame(tex);

            sp.type = cc.Sprite.Type.SIMPLE;

            sp.sizeMode = cc.Sprite.SizeMode.CUSTOM;

           //再次设置node的Size
            courseMainNode.width = parentNode.width;
            courseMainNode.height = parentNode.height;

    }
});

帖子: 2

参与者: 1

阅读整个主题


Viewing all articles
Browse latest Browse all 88737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>