精灵的常用基本属性设置和使用

Sprite是cocos2d-x引擎中最常用的节点称为精灵
可以把精灵看作cocos2d-x中的舞者具有各种动作和表演能力

    // 显示原点坐标, 一般为(0,0) 
    Vec2 orign = Director::getInstance()->getVisibleOrigin();
    // 得到显示的大小
    auto position = Director::getInstance()->getVisibleSize();
    // 设置创建多边形精灵, 性能更好
    auto pinfo = AutoPolygon::generatePolygon("Blover_head.png");
    // 创建精灵
    auto temppng = Sprite::create(pinfo);
    // 设置坐标
    temppng->setPosition(Vec2(position.width / 2 + orign.x, position.height / 2 + orign.y));
    // 设置锚点
    temppng->setAnchorPoint(Vec2(0.5f, 0.5f));
    // 旋转
    temppng->setRotation(20.0f);
    // 缩放
    temppng->setScale(2.0);
    // 倾斜
    temppng->setSkewX(10.0f);
    // 设置颜色
    temppng->setColor(Color3B::RED);
    // 设置透明度 0 - 255// 255 是完全不透明
    temppng->setOpacity(230);
    // 添加到场景
    this->addChild(temppng);

    // Action动作
    // 移动, 用时两秒, X坐标加50
    auto moveBy = MoveBy::create(2, Vec2(50, 3));
    // 精灵执行action
    temppng->runAction(moveBy);
    // 旋转
    auto retateto = RotateTo::create(2, 90);
    temppng->runAction(retateto);
    // 色彩混合, 2秒之内颜色变为
    auto tinto = TintTo::create(2.0f, 120.0f, 232.0f, 254.0f);
    temppng->runAction(tinto);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

梦鸢MoYuan

谢谢投喂!!!QWQ!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值