Adding texture/image support.
authorchsieh <chester.developer@hotmail.com>
Mon, 9 May 2011 16:31:17 +0000 (09:31 -0700)
committerchsieh <chester.developer@hotmail.com>
Mon, 9 May 2011 16:31:17 +0000 (09:31 -0700)
etc/textures/tank-pink.png [new file with mode: 0644]
src/tanks/Game.h
src/tanks/Game.m
src/tanks/unit/Unit.h
src/tanks/unit/Unit.m
tanks.xcodeproj/project.pbxproj

diff --git a/etc/textures/tank-pink.png b/etc/textures/tank-pink.png
new file mode 100644 (file)
index 0000000..27e2aac
Binary files /dev/null and b/etc/textures/tank-pink.png differ
index 625d40e..ca3e13a 100644 (file)
@@ -12,6 +12,6 @@
 
 @interface Game : SPStage
 
-@property(retain) Unit* unit;
+@property(nonatomic,retain) Unit* unit;
 
 @end
index 377fb6d..cda28c0 100644 (file)
 @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
index 1c8fea5..f9a776f 100644 (file)
 
 @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
index 66da593..aab7f6c 100644 (file)
 
 @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;
   
index 559abcf..14c0a97 100644 (file)
                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 */
                49F2DAEC13765004000B6B8C /* TestEntriesViewController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TestEntriesViewController.mm; sourceTree = "<group>"; };
                49F2DB321376632E000B6B8C /* Unit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Unit.h; sourceTree = "<group>"; };
                49F2DB331376632E000B6B8C /* Unit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Unit.m; sourceTree = "<group>"; };
+               4B8B2A3113784D2D00CA4076 /* tank-pink.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "tank-pink.png"; path = "textures/tank-pink.png"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                49F2D9D313764A9B000B6B8C /* etc */ = {
                        isa = PBXGroup;
                        children = (
+                               4B8B2A3313784D3400CA4076 /* textures */,
                                49F2D9D413764A9B000B6B8C /* InfoPlist.strings */,
                                49F2D9D613764A9B000B6B8C /* tanks-Info.plist */,
                        );
                        path = unit;
                        sourceTree = "<group>";
                };
+               4B8B2A3313784D3400CA4076 /* textures */ = {
+                       isa = PBXGroup;
+                       children = (
+                               4B8B2A3113784D2D00CA4076 /* tank-pink.png */,
+                       );
+                       name = textures;
+                       sourceTree = "<group>";
+               };
 /* End PBXGroup section */
 
 /* Begin PBXHeadersBuildPhase section */
                                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;
                };