加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2d-x中精灵的属性

发布时间:2020-12-14 20:28:45 所属栏目:百科 来源:网络整理
导读:// This is how to create an spriteauto mySprite = Sprite::create("mysprite.png"); // this is how to change the properties of the spritemySprite-setPosition(Vec2(500,0)); mySprite-setRotation(40); mySprite-setScale(2.0); // sets scale X and
// This is how to create an sprite
auto mySprite = Sprite::create("mysprite.png");
 
// this is how to change the properties of the sprite
mySprite->setPosition(Vec2(500,0));
 
mySprite->setRotation(40);
 
mySprite->setScale(2.0); // sets scale X and Y uniformly
 
mySprite->setAchorVec2(0,0);



通过代码mySprite->setPosition(Vec2(500,0));将坐标进行重新设置,


mySprite->setRotation(40);对精灵的翻转进行设定,

mySprite->setScale(2.0);将精灵进行缩放,

最后,所有的节点Node对象(注意Sprite精灵类是Node节点类的子类)都有一个称为锚点的值。我们之前还没有提过这个概念,现在时机正好。你可以将锚点想象为在对精灵进行坐标点设定的时候精灵所自身使用的坐标点。

通过代码mySprite->setAchorVec2(0,0);将游戏中的精灵锚点设定为(0,0)坐标,那么所有使用代码setPosition()进行坐标设定的精灵都会以自身的左下角来进行对齐。

如果你有注意锚点的位置, 你会发现锚点对节点来说是非常有用的。你甚至可以通过调整精灵的锚点来模拟动态效果。 现在我们已经可以很好地使用精灵了。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读