From 597dcb0eb43b3ec84bbfea9de5de84d8e58a7aef Mon Sep 17 00:00:00 2001 From: Lars Birkemose Date: Mon, 2 Mar 2015 13:38:11 +0100 Subject: [PATCH] CCSpriteGrid updates --- Extensions/CCSpriteGrid/CCSpriteGrid.h | 5 +++ Extensions/CCSpriteGrid/CCSpriteGrid.m | 42 ++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Extensions/CCSpriteGrid/CCSpriteGrid.h b/Extensions/CCSpriteGrid/CCSpriteGrid.h index 9c56bfa..a855b6a 100644 --- a/Extensions/CCSpriteGrid/CCSpriteGrid.h +++ b/Extensions/CCSpriteGrid/CCSpriteGrid.h @@ -43,6 +43,7 @@ - (void)setGridWidth:(NSUInteger)width andHeight:(NSUInteger)height; - (void)resetGrid; +- (void)markAsDirty; - (BOOL)isEdge:(NSUInteger)index; @@ -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; diff --git a/Extensions/CCSpriteGrid/CCSpriteGrid.m b/Extensions/CCSpriteGrid/CCSpriteGrid.m index 543e819..9332f02 100644 --- a/Extensions/CCSpriteGrid/CCSpriteGrid.m +++ b/Extensions/CCSpriteGrid/CCSpriteGrid.m @@ -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 @@ -206,6 +206,13 @@ - (void)createGrid // ----------------------------------------------------------------------- +- (void)markAsDirty +{ + _dirty = YES; +} + +// ----------------------------------------------------------------------- + - (void)resetGrid { if (!_dirty) return; @@ -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)