CCTexture Class Reference
| Inherits from | NSObject |
| Declared in | CCTexture.h |
Overview
CCTexture2D class. This class allows to easily create OpenGL 2D textures from images, text or raw data. The created CCTexture2D object will always have power-of-two dimensions. Depending on how you create the CCTexture2D object, the actual image area of the texture might be smaller than the texture dimensions - i.e. “contentSize” != (pixelsWide, pixelsHigh) and (maxS, maxT) != (1.0, 1.0). Be aware that the content of the generated textures will be upside-down!
Extensions to make it easy to create a CCTexture2D object from an image file. Note that RGBA type textures will have their alpha premultiplied - use the blending mode (GL_ONE, GL_ONE_MINUS_SRC_ALPHA).
Tasks
Initializing a CCTexture Object
Creating a CCTexture Object
Accessing The Texture Attributes
-
pixelFormatproperty -
pixelWidthproperty -
pixelHeightproperty -
contentSizeInPixelsproperty -
premultipliedAlphaproperty -
antialiasedproperty -
contentScaleproperty -
– contentSize -
– createSpriteFrame
Image Methods
PixelFormat Methods
Properties
antialiased
True if antialised.
@property (nonatomic, assign, getter=isAntialiased) BOOL antialiasedDeclared In
CCTexture.hcontentScale
Returns the contentScale of the texture. In general “HD” textures return a contentScale of 2.0, while non-HD textures return 1.0. Loading behavior is changed by [CCFileUtils set*ContentScaleFactor:]. The value can be changed manually if you want to force a certain content scale.
@property (nonatomic, readwrite) CGFloat contentScaleDeclared In
CCTexture.hcontentSizeInPixels
Returns content size of the texture in pixels.
@property (nonatomic, readonly, nonatomic) CGSize contentSizeInPixelsDeclared In
CCTexture.hpixelFormat
Pixel format of the texture.
@property (nonatomic, readonly) CCTexturePixelFormat pixelFormatDeclared In
CCTexture.hpixelHeight
Height in pixels.
@property (nonatomic, readonly) NSUInteger pixelHeightDeclared In
CCTexture.hClass Methods
bitsPerPixelForFormat:
Helper functions that returns bits per pixels for a given format.
+ (NSUInteger)bitsPerPixelForFormat:(CCTexturePixelFormat)formatParameters
- format
Format to query for pixelsize.
Return Value
Number of bits for pixelformat.
Declared In
CCTexture.hdefaultAlphaPixelFormat
Returns the alpha pixel format.
+ (CCTexturePixelFormat)defaultAlphaPixelFormatReturn Value
The pixel format.
Declared In
CCTexture.hsetDefaultAlphaPixelFormat:
Sets the default pixel format for CGImages that contains alpha channel.
+ (void)setDefaultAlphaPixelFormat:(CCTexturePixelFormat)formatParameters
- format
Format to use with texture.
Discussion
How does it work ? If the image is an RGBA (with Alpha) then the default pixel format will be used (it can be a 8-bit, 16-bit or 32-bit texture). If the image is an RGB (without Alpha) then: If the default pixel format is RGBA8888 then a RGBA8888 (32-bit) will be used. Otherwise a RGB565 (16-bit texture) will be used.
This parameter is not valid for PVR / PVR.CCZ images.
Declared In
CCTexture.htextureWithFile:
Creates and returns a new texture, based on the specified file path value. If the texture has already been loaded, and resides in cache, the previously created texture is returned.
+ (instancetype)textureWithFile:(NSString *)fileParameters
- file
File path to load (should not include any suffixes).
Return Value
The CCTexture object.
Declared In
CCTexture.hInstance Methods
bitsPerPixelForFormat
Returns the bits-per-pixel of the in-memory OpenGL texture.
- (NSUInteger)bitsPerPixelForFormatReturn Value
Number of bits per pixel.
Declared In
CCTexture.hcontentSize
Returns the content size of the texture in points.
- (CGSize)contentSizeDeclared In
CCTexture.hcreateSpriteFrame
Creates a sprite frame from the texture.
- (CCSpriteFrame *)createSpriteFrameReturn Value
A new sprite frame.
Declared In
CCTexture.hinitWithCGImage:contentScale:
Initializes and returns a texture from a CGImage object.
- (id)initWithCGImage:(CGImageRef)cgImage contentScale:(CGFloat)contentScaleParameters
- cgImage
CGImage to use for texture
- contentScale
Content scale.
Return Value
An initialized CCTexture object.
Declared In
CCTexture.hinitWithData:pixelFormat:pixelsWide:pixelsHigh:contentSizeInPixels:contentScale:
Initializes and returns a texture object using the specified data, pixelFormat, width, height, sizeInPixels and contentScale values.
- (id)initWithData:(const void *)data pixelFormat:(CCTexturePixelFormat)pixelFormat pixelsWide:(NSUInteger)width pixelsHigh:(NSUInteger)height contentSizeInPixels:(CGSize)sizeInPixels contentScale:(CGFloat)contentScaleParameters
- data
Pointer to a buffer containing the raw data.
- pixelFormat
Pixelformat of the data
- width
Width if the texture
- height
Height of the texture
- sizeInPixels
Size of resulting texture.
- contentScale
Content scale.
Return Value
An initialized CCTexture Object.
Declared In
CCTexture.h