From: chsieh Date: Tue, 17 May 2011 04:21:48 +0000 (-0700) Subject: Merge from master. X-Git-Url: http://git.less.ly:3516/?a=commitdiff_plain;h=262b134d192d10797b47509f455ce09213a3e5b2;p=tanks-ios.git Merge from master. --- 262b134d192d10797b47509f455ce09213a3e5b2 diff --cc src/game/actor/Unit.h index 0000000,c6650c2..5ce2e6d mode 000000,100644..100644 --- a/src/game/actor/Unit.h +++ b/src/game/actor/Unit.h @@@ -1,0 -1,21 +1,24 @@@ + #import "Sparrow.h" + #import "render/QQSparrowExtensions.h" + + #import "game/actor/Actor.h" + #import "physics/World.h" + + ++//////////////////////////////////////////////////////////////////////////////////// + @interface Unit : Actor { + + @private + SPDisplayObject* _shape; + } + ++//////////////////////////////////////////////////////////////////////////////////// + @property (nonatomic, retain, readwrite) SPDisplayObject* shape; + ++//////////////////////////////////////////////////////////////////////////////////// + - (id) initWithFile:(NSString*)fileName atX:(float)x y:(float)y; + - (id) initWithShape:(SPDisplayObject*)aShape; + + - (void) onTouch:(SPTouchEvent*)event; + + @end diff --cc src/game/actor/Unit.mm index 0000000,f37dd31..88e057a mode 000000,100644..100644 --- a/src/game/actor/Unit.mm +++ b/src/game/actor/Unit.mm @@@ -1,0 -1,52 +1,60 @@@ + #import "Sparrow.h" + #import "Unit.h" + + ++//////////////////////////////////////////////////////////////////////////////////// + @implementation Unit + ++//////////////////////////////////////////////////////////////////////////////////// + @synthesize shape = _shape; + ++//////////////////////////////////////////////////////////////////////////////////// + - (id) init { + return [self initWithShape:[[SPQuad quadWithWidth:32 height:32 color:0xff0000] setPositionX:50 y:50]]; + } + ++//////////////////////////////////////////////////////////////////////////////////// + - (id) initWithFile:(NSString*)fileName atX:(float)x y:(float)y { + return [self initWithShape:[[[[SPImage alloc] initWithContentsOfFile:fileName] autorelease] setPositionX:x y:y]]; + } + ++//////////////////////////////////////////////////////////////////////////////////// + - (id) initWithShape:(SPDisplayObject*)aShape { + if ((self = [super init])) { + self.shape = aShape; + [self.game addEventListener:@selector(onTouch:) atObject:self forType:SP_EVENT_TYPE_TOUCH]; + } + return self; + } + ++//////////////////////////////////////////////////////////////////////////////////// + - (void) dealloc { + [self.game removeEventListener:@selector(onTouch:) atObject:self forType:SP_EVENT_TYPE_TOUCH]; + [self.game removeChild:_shape]; + [_shape release]; + [super dealloc]; + } + ++//////////////////////////////////////////////////////////////////////////////////// + - (void) setShape:(SPDisplayObject*)newShape { + if (_shape != newShape) { + [self.game removeChild:_shape]; + [_shape release]; + _shape = [newShape retain]; + [self.game addChild:_shape]; + } + } + ++//////////////////////////////////////////////////////////////////////////////////// + - (void) onTouch:(SPTouchEvent*)event { + NSLog(@"%@ onTouch! shape=%@ parent=%@", self, self.shape, self.shape.parent); + SPTouch* touch = [[event touchesWithTarget:self.shape.parent] anyObject]; + if (touch) { + SPPoint* touchPosition = [touch locationInSpace:self.shape.parent]; + self.shape.x = touchPosition.x - self.shape.width / 2.0f; + self.shape.y = touchPosition.y - self.shape.height / 2.0f; + } + } + + + @end diff --cc src/render/animation/AnimationContainer.h index 21a6e53,4b4d16c..8cb0020 --- a/src/render/animation/AnimationContainer.h +++ b/src/render/animation/AnimationContainer.h @@@ -1,16 -1,5 +1,6 @@@ - // - // AnimationContainer.h - // tanks - // - // Created by Doris Chen on 5/12/11. - // Copyright 2011 __MyCompanyName__. All rights reserved. - // - - #import - #import "SPTextureAtlas.h" + //////////////////////////////////////////////////////////////////////////////////// @interface AnimationContainer : NSObject { }