精灵(CCSprite)

来源:互联网 发布:mac与iphone传文件 编辑:程序博客网 时间:2024/05/01 18:04

什么是精灵(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. See Actions  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 通过缓存帧来更换

0 0
原创粉丝点击