PageRenderTime 39ms CodeModel.GetById 11ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 1ms

/libs/cocos2d/CCSpriteFrame.h

http://github.com/kstenerud/ObjectAL-for-iPhone
C Header | 160 lines | 48 code | 28 blank | 84 comment | 0 complexity | 4fb325dc4daa527fde9dd2db6eafd2d5 MD5 | raw file
  1/*
  2 * cocos2d for iPhone: http://www.cocos2d-iphone.org
  3 *
  4 * Copyright (c) 2008-2010 Ricardo Quesada
  5 * 
  6 * Permission is hereby granted, free of charge, to any person obtaining a copy
  7 * of this software and associated documentation files (the "Software"), to deal
  8 * in the Software without restriction, including without limitation the rights
  9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10 * copies of the Software, and to permit persons to whom the Software is
 11 * furnished to do so, subject to the following conditions:
 12 * 
 13 * The above copyright notice and this permission notice shall be included in
 14 * all copies or substantial portions of the Software.
 15 * 
 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 22 * THE SOFTWARE.
 23 *
 24 */
 25
 26#import <Foundation/Foundation.h>
 27#import "CCNode.h"
 28#import "CCProtocols.h"
 29
 30#pragma mark -
 31#pragma mark CCSpriteFrame
 32
 33/** A CCSpriteFrame has:
 34	- texture: A CCTexture2D that will be used by the CCSprite
 35	- rectangle: A rectangle of the texture
 36
 37
 38 You can modify the frame of a CCSprite by doing:
 39 
 40	CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:texture rect:rect offset:offset];
 41	[sprite setDisplayFrame:frame];
 42 */
 43@interface CCSpriteFrame : NSObject <NSCopying>
 44{
 45	CGRect			rect_;
 46	BOOL			rotated_;
 47	CGPoint			offset_;
 48	CGSize			originalSize_;
 49	CCTexture2D		*texture_;
 50}
 51/** rect of the frame */
 52@property (nonatomic,readwrite) CGRect rect;
 53
 54/** whether or not the rect of the frame is rotated ( x = x+width, y = y+height, width = height, height = width ) */
 55@property (nonatomic,readwrite) BOOL rotated;
 56
 57/** offset of the frame */
 58@property (nonatomic,readwrite) CGPoint offset;
 59
 60/** original size of the trimmed image */
 61@property (nonatomic,readwrite) CGSize originalSize;
 62
 63/** texture of the frame */
 64@property (nonatomic, retain, readwrite) CCTexture2D *texture;
 65
 66/** Create a CCSpriteFrame with a texture, rect and offset.
 67 It is assumed that the frame was not trimmed.
 68 */
 69+(id) frameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect offset:(CGPoint)offset;
 70
 71/** Create a CCSpriteFrame with a texture, rect, offset and originalSize.
 72 The originalSize is the size in pixels of the frame before being trimmed.
 73 */
 74+(id) frameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect offset:(CGPoint)offset originalSize:(CGSize)originalSize;
 75
 76/** Create a CCSpriteFrame with a texture, rect, rotated, offset and originalSize.
 77 The originalSize is the size in pixels of the frame before being trimmed.
 78 */
 79+(id) frameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize;
 80
 81/** Initializes a CCSpriteFrame with a texture, rect and offset.
 82 It is assumed that the frame was not trimmed.
 83 */
 84-(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect offset:(CGPoint)offset;
 85
 86/** Initializes a CCSpriteFrame with a texture, rect, offset and originalSize.
 87 The originalSize is the size in pixels of the frame before being trimmed.
 88 */
 89-(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect offset:(CGPoint)offset originalSize:(CGSize)originalSize;
 90
 91/** Initializes a CCSpriteFrame with a texture, rect, rotated, offset and originalSize.
 92 The originalSize is the size in pixels of the frame before being trimmed.
 93 */
 94-(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize;
 95
 96@end
 97
 98#pragma mark -
 99#pragma mark CCAnimation
100
101/** an Animation object used within Sprites to perform animations */
102@interface CCAnimation : NSObject
103{
104	NSString			*name_;
105	float				delay_;
106	NSMutableArray		*frames_;
107}
108
109/** name of the animation */
110@property (nonatomic,readwrite,retain) NSString *name;
111/** delay between frames in seconds. */
112@property (nonatomic,readwrite,assign) float delay;
113/** array of frames */
114@property (nonatomic,readwrite,retain) NSMutableArray *frames;
115
116/** Creates a CCAnimation with a name
117 @since v0.99.3
118 */
119+(id) animationWithName:(NSString*)name;
120
121/** Creates a CCAnimation with a name and frames
122 @since v0.99.3
123 */
124+(id) animationWithName:(NSString*)name frames:(NSArray*)frames;
125
126/** Creates a CCAnimation with a name and delay between frames. */
127+(id) animationWithName:(NSString*)name delay:(float)delay;
128
129/** Creates a CCAnimation with a name, delay and an array of CCSpriteFrames. */
130+(id) animationWithName:(NSString*)name delay:(float)delay frames:(NSArray*)frames;
131
132/** Initializes a CCAnimation with a name
133 @since v0.99.3
134 */
135-(id) initWithName:(NSString*)name;
136
137/** Initializes a CCAnimation with a name and frames
138 @since v0.99.3
139 */
140-(id) initWithName:(NSString*)name frames:(NSArray*)frames;
141
142/** Initializes a CCAnimation with a name and delay between frames. */
143-(id) initWithName:(NSString*)name delay:(float)delay;
144
145/** Initializes a CCAnimation with a name, delay and an array of CCSpriteFrames. */
146-(id) initWithName:(NSString*)name delay:(float)delay frames:(NSArray*)frames;
147
148/** Adds a frame to a CCAnimation. */
149-(void) addFrame:(CCSpriteFrame*)frame;
150
151/** Adds a frame with an image filename. Internally it will create a CCSpriteFrame and it will add it.
152 Added to facilitate the migration from v0.8 to v0.9.
153 */
154-(void) addFrameWithFilename:(NSString*)filename;
155
156/** Adds a frame with a texture and a rect. Internally it will create a CCSpriteFrame and it will add it.
157 Added to facilitate the migration from v0.8 to v0.9.
158 */
159-(void) addFrameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect;
160@end