Skip to content

Commit

Permalink
CCSpriteGrid updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkemose committed Mar 2, 2015
1 parent 48d4767 commit 597dcb0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Extensions/CCSpriteGrid/CCSpriteGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

- (void)setGridWidth:(NSUInteger)width andHeight:(NSUInteger)height;
- (void)resetGrid;
- (void)markAsDirty;

- (BOOL)isEdge:(NSUInteger)index;

Expand All @@ -54,6 +55,10 @@
- (void)adjustTextureCoordinate:(NSUInteger)index adjustment:(CGPoint)adjustment;
- (void)adjustColor:(NSUInteger)index adjustment:(CCColor *)adjustment;

- (void)setVertex:(NSUInteger)index position:(CGPoint)position;
- (void)setTextureCoordinate:(NSUInteger)index coordinate:(CGPoint)coordinate;
- (void)setColor:(NSUInteger)index color:(CCColor *)color;

- (void)resetVertex:(NSUInteger)index;
- (void)resetTextureCoordinate:(NSUInteger)index;
- (void)resetColor:(NSUInteger)index;
Expand Down
42 changes: 40 additions & 2 deletions Extensions/CCSpriteGrid/CCSpriteGrid.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ @implementation CCSpriteGrid

// -----------------------------------------------------------------------

- (instancetype)init
- (id)initWithTexture:(CCTexture *)texture rect:(CGRect)rect rotated:(BOOL)rotated
{
self = [super init];
self = [super initWithTexture:texture rect:rect rotated:rotated];
NSAssert(self, @"Unable to create class CCSpriteGrid");
// initialize

Expand Down Expand Up @@ -206,6 +206,13 @@ - (void)createGrid

// -----------------------------------------------------------------------

- (void)markAsDirty
{
_dirty = YES;
}

// -----------------------------------------------------------------------

- (void)resetGrid
{
if (!_dirty) return;
Expand Down Expand Up @@ -275,6 +282,37 @@ - (void)adjustColor:(NSUInteger)index adjustment:(CCColor *)adjustment
_dirty = YES;
}

// -----------------------------------------------------------------------
// more setters

- (void)setVertex:(NSUInteger)index position:(CGPoint)position
{
NSAssert(index < _vertexCount, @"Invalid vertex index");
if (_vertexIsLocked[index]) return;
_vertex[index].position.x = position.x;
_vertex[index].position.y = position.y;
_dirty = YES;
}

- (void)setTextureCoordinate:(NSUInteger)index coordinate:(CGPoint)coordinate
{
NSAssert(index < _vertexCount, @"Invalid vertex index");
if (_vertexIsLocked[index]) return;
_vertex[index].texCoord1.v[0] = (coordinate.x / _textureSize.width);
_vertex[index].texCoord1.v[1] = (coordinate.y / _textureSize.height);
_dirty = YES;
}

- (void)setColor:(NSUInteger)index color:(CCColor *)color
{
NSAssert(index < _vertexCount, @"Invalid vertex index");
if (_vertexIsLocked[index]) return;
_vertex[index].color.r = color.red;
_vertex[index].color.g = color.green;
_vertex[index].color.b = color.blue;
_dirty = YES;
}

// -----------------------------------------------------------------------
// resetters (haha)

Expand Down

0 comments on commit 597dcb0

Please sign in to comment.