/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. #import <Foundation/Foundation.h>
  26. #import "CCNode.h"
  27. #import "CCProtocols.h"
  28. #pragma mark -
  29. #pragma mark CCSpriteFrame
  30. /** A CCSpriteFrame has:
  31. - texture: A CCTexture2D that will be used by the CCSprite
  32. - rectangle: A rectangle of the texture
  33. You can modify the frame of a CCSprite by doing:
  34. CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:texture rect:rect offset:offset];
  35. [sprite setDisplayFrame:frame];
  36. */
  37. @interface CCSpriteFrame : NSObject <NSCopying>
  38. {
  39. CGRect rect_;
  40. BOOL rotated_;
  41. CGPoint offset_;
  42. CGSize originalSize_;
  43. CCTexture2D *texture_;
  44. }
  45. /** rect of the frame */
  46. @property (nonatomic,readwrite) CGRect rect;
  47. /** whether or not the rect of the frame is rotated ( x = x+width, y = y+height, width = height, height = width ) */
  48. @property (nonatomic,readwrite) BOOL rotated;
  49. /** offset of the frame */
  50. @property (nonatomic,readwrite) CGPoint offset;
  51. /** original size of the trimmed image */
  52. @property (nonatomic,readwrite) CGSize originalSize;
  53. /** texture of the frame */
  54. @property (nonatomic, retain, readwrite) CCTexture2D *texture;
  55. /** Create a CCSpriteFrame with a texture, rect and offset.
  56. It is assumed that the frame was not trimmed.
  57. */
  58. +(id) frameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect offset:(CGPoint)offset;
  59. /** Create a CCSpriteFrame with a texture, rect, offset and originalSize.
  60. The originalSize is the size in pixels of the frame before being trimmed.
  61. */
  62. +(id) frameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect offset:(CGPoint)offset originalSize:(CGSize)originalSize;
  63. /** Create a CCSpriteFrame with a texture, rect, rotated, offset and originalSize.
  64. The originalSize is the size in pixels of the frame before being trimmed.
  65. */
  66. +(id) frameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize;
  67. /** Initializes a CCSpriteFrame with a texture, rect and offset.
  68. It is assumed that the frame was not trimmed.
  69. */
  70. -(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect offset:(CGPoint)offset;
  71. /** Initializes 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) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect offset:(CGPoint)offset originalSize:(CGSize)originalSize;
  75. /** Initializes a CCSpriteFrame with a texture, rect, rotated, offset and originalSize.
  76. The originalSize is the size in pixels of the frame before being trimmed.
  77. */
  78. -(id) initWithTexture:(CCTexture2D*)texture rect:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize;
  79. @end
  80. #pragma mark -
  81. #pragma mark CCAnimation
  82. /** an Animation object used within Sprites to perform animations */
  83. @interface CCAnimation : NSObject
  84. {
  85. NSString *name_;
  86. float delay_;
  87. NSMutableArray *frames_;
  88. }
  89. /** name of the animation */
  90. @property (nonatomic,readwrite,retain) NSString *name;
  91. /** delay between frames in seconds. */
  92. @property (nonatomic,readwrite,assign) float delay;
  93. /** array of frames */
  94. @property (nonatomic,readwrite,retain) NSMutableArray *frames;
  95. /** Creates a CCAnimation with a name
  96. @since v0.99.3
  97. */
  98. +(id) animationWithName:(NSString*)name;
  99. /** Creates a CCAnimation with a name and frames
  100. @since v0.99.3
  101. */
  102. +(id) animationWithName:(NSString*)name frames:(NSArray*)frames;
  103. /** Creates a CCAnimation with a name and delay between frames. */
  104. +(id) animationWithName:(NSString*)name delay:(float)delay;
  105. /** Creates a CCAnimation with a name, delay and an array of CCSpriteFrames. */
  106. +(id) animationWithName:(NSString*)name delay:(float)delay frames:(NSArray*)frames;
  107. /** Initializes a CCAnimation with a name
  108. @since v0.99.3
  109. */
  110. -(id) initWithName:(NSString*)name;
  111. /** Initializes a CCAnimation with a name and frames
  112. @since v0.99.3
  113. */
  114. -(id) initWithName:(NSString*)name frames:(NSArray*)frames;
  115. /** Initializes a CCAnimation with a name and delay between frames. */
  116. -(id) initWithName:(NSString*)name delay:(float)delay;
  117. /** Initializes a CCAnimation with a name, delay and an array of CCSpriteFrames. */
  118. -(id) initWithName:(NSString*)name delay:(float)delay frames:(NSArray*)frames;
  119. /** Adds a frame to a CCAnimation. */
  120. -(void) addFrame:(CCSpriteFrame*)frame;
  121. /** Adds a frame with an image filename. Internally it will create a CCSpriteFrame and it will add it.
  122. Added to facilitate the migration from v0.8 to v0.9.
  123. */
  124. -(void) addFrameWithFilename:(NSString*)filename;
  125. /** Adds a frame with a texture and a rect. Internally it will create a CCSpriteFrame and it will add it.
  126. Added to facilitate the migration from v0.8 to v0.9.
  127. */
  128. -(void) addFrameWithTexture:(CCTexture2D*)texture rect:(CGRect)rect;
  129. @end