From: chsieh Date: Mon, 9 May 2011 16:31:17 +0000 (-0700) Subject: Adding texture/image support. X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=39c64f2f5c62d13f34df73c9e77280624b49ad14;p=tanks-ios.git Adding texture/image support. --- diff --git a/etc/textures/tank-pink.png b/etc/textures/tank-pink.png new file mode 100644 index 0000000..27e2aac Binary files /dev/null and b/etc/textures/tank-pink.png differ diff --git a/src/tanks/Game.h b/src/tanks/Game.h index 625d40e..ca3e13a 100644 --- a/src/tanks/Game.h +++ b/src/tanks/Game.h @@ -12,6 +12,6 @@ @interface Game : SPStage -@property(retain) Unit* unit; +@property(nonatomic,retain) Unit* unit; @end diff --git a/src/tanks/Game.m b/src/tanks/Game.m index 377fb6d..cda28c0 100644 --- a/src/tanks/Game.m +++ b/src/tanks/Game.m @@ -14,17 +14,17 @@ @synthesize unit; - (id)initWithWidth:(float)width height:(float)height { - if ( (self = [super initWithWidth:width height:height]) ){ - unit = [[Unit alloc] initWithWidth:100 height:100 X:50 Y:50]; - [self addEventListener:@selector(onTouch:) atObject:unit forType:SP_EVENT_TYPE_TOUCH]; - [self addChild:unit.quad]; - } - return self; + if ( (self = [super initWithWidth:width height:height]) ){ + unit = [[Unit alloc] initWithFile:@"tank-pink.png" atX: 50.0f andY:50.0f]; + [self addEventListener:@selector(onTouch:) atObject:unit forType:SP_EVENT_TYPE_TOUCH]; + [self addChild:unit.quad]; + } + return self; } - (void)dealloc { - [self setUnit:nil]; - [super dealloc]; + [self setUnit:nil]; + [super dealloc]; } @end \ No newline at end of file diff --git a/src/tanks/unit/Unit.h b/src/tanks/unit/Unit.h index 1c8fea5..f9a776f 100644 --- a/src/tanks/unit/Unit.h +++ b/src/tanks/unit/Unit.h @@ -15,6 +15,10 @@ @property(nonatomic, retain) SPQuad* quad; --(Unit*)initWithWidth:(int)width height:(int)height X:(int)x Y:(int)y; +-(void)dealloc; +-(Unit*)initWithWidth:(float)width height:(float)height X:(float)x Y:(float)y color:(int)color; +-(Unit*)initWithFile:(NSString*)fileName atX:(float)x andY:(float)y; + -(void)onTouch:(SPTouchEvent*)event; + @end diff --git a/src/tanks/unit/Unit.m b/src/tanks/unit/Unit.m index 66da593..aab7f6c 100644 --- a/src/tanks/unit/Unit.m +++ b/src/tanks/unit/Unit.m @@ -13,9 +13,23 @@ @synthesize quad; --(Unit*)initWithWidth:(int)width height:(int)height X:(int)x Y:(int)y { - quad = [SPQuad quadWithWidth:width height:height]; - quad.color = 0xff0000; +-(void)dealloc { + [quad release]; + [super dealloc]; +} + +-(Unit*)initWithWidth:(float)width height:(float)height X:(float)x Y:(float)y color:(int)color { + quad = [[SPQuad alloc] initWithWidth:width height:height]; + quad.color = color; + quad.x = x; + quad.y = y; + + return self; +} + +-(Unit*)initWithFile:(NSString*)fileName atX:(float)x andY:(float)y +{ + quad = [[SPImage alloc] initWithContentsOfFile:fileName]; quad.x = x; quad.y = y; diff --git a/tanks.xcodeproj/project.pbxproj b/tanks.xcodeproj/project.pbxproj index 559abcf..14c0a97 100644 --- a/tanks.xcodeproj/project.pbxproj +++ b/tanks.xcodeproj/project.pbxproj @@ -126,6 +126,7 @@ 49F2DAF313765004000B6B8C /* GLES-Render.mm in Sources */ = {isa = PBXBuildFile; fileRef = 49F2DAE713765004000B6B8C /* GLES-Render.mm */; }; 49F2DB341376632E000B6B8C /* Unit.h in Headers */ = {isa = PBXBuildFile; fileRef = 49F2DB321376632E000B6B8C /* Unit.h */; }; 49F2DB351376632E000B6B8C /* Unit.m in Sources */ = {isa = PBXBuildFile; fileRef = 49F2DB331376632E000B6B8C /* Unit.m */; }; + 4B8B2A3213784D2D00CA4076 /* tank-pink.png in Resources */ = {isa = PBXBuildFile; fileRef = 4B8B2A3113784D2D00CA4076 /* tank-pink.png */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -279,6 +280,7 @@ 49F2DAEC13765004000B6B8C /* TestEntriesViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestEntriesViewController.mm; sourceTree = ""; }; 49F2DB321376632E000B6B8C /* Unit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Unit.h; sourceTree = ""; }; 49F2DB331376632E000B6B8C /* Unit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Unit.m; sourceTree = ""; }; + 4B8B2A3113784D2D00CA4076 /* tank-pink.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "tank-pink.png"; path = "textures/tank-pink.png"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -436,6 +438,7 @@ 49F2D9D313764A9B000B6B8C /* etc */ = { isa = PBXGroup; children = ( + 4B8B2A3313784D3400CA4076 /* textures */, 49F2D9D413764A9B000B6B8C /* InfoPlist.strings */, 49F2D9D613764A9B000B6B8C /* tanks-Info.plist */, ); @@ -673,6 +676,14 @@ path = unit; sourceTree = ""; }; + 4B8B2A3313784D3400CA4076 /* textures */ = { + isa = PBXGroup; + children = ( + 4B8B2A3113784D2D00CA4076 /* tank-pink.png */, + ); + name = textures; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -807,6 +818,7 @@ 49F2D9C713764666000B6B8C /* MainWindow_iPad.xib in Resources */, 49F2D9C913764666000B6B8C /* MainWindow_iPhone.xib in Resources */, 49F2D9D713764A9B000B6B8C /* InfoPlist.strings in Resources */, + 4B8B2A3213784D2D00CA4076 /* tank-pink.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; };