zoukankan      html  css  js  c++  java
  • cocos2dx中的精灵CCSprite

    什么是精灵(CCSprite),在官网文档中是这么定义的

    Sprites

    A cocos2d CCSprite is similar to sprites you find in other game engines. It is a 2D image that can be moved, rotated, scaled, animated, and undergo other transformations. Sprites (implemented using the CCSprite class) can have other sprites as children. When a parent is transformed, all its children are transformed as well. Because sprites are a subclass of CCNode, they can be transformed manually or by using CCActions. SeeActions for more information.

    他们说Cocos2d-x的精灵和其他游戏引擎中的精灵一样,是一个2D图像,能被移动,旋转,压缩,活动以及其他的变换。精灵可以拥有别的精灵作为儿子,当父精灵变化时,儿子精灵也会跟随着变换。


    怎么创建精灵对象:

    在cocos2dx中,精灵是由类CCSprite封装的,创建精灵的方法有:

    1) 从文件创建

    CCSprite::create()

    2)从帧缓存创建


    默认属性:

    默认锚点为0.5,0.5

    默认位置为0,0

    默认contentSize为图片像素尺寸


    常用属性和操作:

    缩放 setScale, setScaleX, setScaleY

    旋转 setRotation

    透明度 setOpacity

    锚点 setAnchorPoint

    位置 setPosition

    反转 setFlipX,setFlipY

    隐藏/显示 setVisible

    颜色 setColor

    zOrder 创建时指定,不可更改,只能通过父对象更改

    设置纹理区域 setTextureRect


    换图片

    setTexture 直接通过图片换

    setDisplayFrame 通过缓存帧来更换





  • 相关阅读:
    【爬坑】在 IDEA 中运行 Hadoop 程序 报 winutils.exe 不存在错误解决方案
    【爬坑】Vim 文档加密 & 解密
    Maven 安装配置
    2014/11/23 条件查询
    2014/11/21
    2014/11/20 SQL简单命令
    2014/11/19 SQL Server基础
    7、数组
    6、循环、跳转、异常语句,string类、math、datetime
    5、循环语句、穷举
  • 原文地址:https://www.cnblogs.com/new0801/p/6177191.html
Copyright © 2011-2022 走看看