Skip to content

Commit 6caf6b3

Browse files
committed
Minor CCResponder design cleanup
1 parent 7e66428 commit 6caf6b3

File tree

4 files changed

+32
-25
lines changed

4 files changed

+32
-25
lines changed

cocos2d/CCNode.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -393,28 +393,6 @@ A common user pattern in building a Cocos2d game is to subclass CCNode, add it t
393393
/** The z order of the node relative to its "siblings": children of the same parent. */
394394
@property(nonatomic,assign) NSInteger zOrder;
395395

396-
397-
/// -----------------------------------------------------------------------
398-
/// @name Hit tests
399-
/// -----------------------------------------------------------------------
400-
401-
/**
402-
* Check if a touch is inside the node.
403-
* To allow for custom detection, override this method.
404-
*
405-
* @param pos World position.
406-
*
407-
* @return Returns true, if the position is inside the node.
408-
*/
409-
- (BOOL)hitTestWithWorldPos:(CGPoint)pos;
410-
411-
/**
412-
* Expands ( or contracts ) the hit area of the node.
413-
* The expansion is calculated as a margin around the sprite, in points.
414-
*/
415-
@property (nonatomic, assign) float hitAreaExpansion;
416-
417-
418396
/// -----------------------------------------------------------------------
419397
/// @name Scene Management
420398
/// -----------------------------------------------------------------------

cocos2d/CCNode.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ - (CGPoint)convertToWindowSpace:(CGPoint)nodePoint
16181618
- (BOOL)hitTestWithWorldPos:(CGPoint)pos
16191619
{
16201620
pos = [self convertToNodeSpace:pos];
1621-
CGPoint offset = ccp(-_hitAreaExpansion, -_hitAreaExpansion);
1621+
CGPoint offset = ccp(-self.hitAreaExpansion, -self.hitAreaExpansion);
16221622
CGSize size = CGSizeMake(self.contentSizeInPoints.width - offset.x, self.contentSizeInPoints.height - offset.y);
16231623
if ((pos.y < offset.y) || (pos.y > size.height) || (pos.x < offset.x) || (pos.x > size.width)) return(NO);
16241624

@@ -1627,7 +1627,6 @@ - (BOOL)hitTestWithWorldPos:(CGPoint)pos
16271627

16281628
// -----------------------------------------------------------------
16291629

1630-
16311630
#pragma mark - CCColor methods
16321631

16331632
@synthesize cascadeColorEnabled=_cascadeColorEnabled;

cocos2d/CCResponder.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
*/
4141
@interface CCResponder : NSObject
4242

43+
/// -----------------------------------------------------------------------
44+
/// @name Basic responder control
45+
/// -----------------------------------------------------------------------
4346

4447
/** Enables user interaction on a node. */
4548
@property ( nonatomic, assign, getter = isUserInteractionEnabled ) BOOL userInteractionEnabled;
@@ -61,6 +64,12 @@
6164
*/
6265
@property (nonatomic, assign, getter = isExclusiveTouch) BOOL exclusiveTouch;
6366

67+
/**
68+
* Expands ( or contracts ) the hit area of the node.
69+
* The expansion is calculated as a margin around the sprite, in points.
70+
*/
71+
@property (nonatomic, assign) float hitAreaExpansion;
72+
6473
/// -----------------------------------------------------------------------
6574
/// @name Initializing a CCResponder Object
6675
/// -----------------------------------------------------------------------
@@ -72,8 +81,21 @@
7281
*/
7382
- (id)init;
7483

75-
#if ( TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR )
84+
/// -----------------------------------------------------------------------
85+
/// @name Hit tests
86+
/// -----------------------------------------------------------------------
7687

88+
/**
89+
* Check if a touch is inside the node.
90+
* To allow for custom detection, override this method.
91+
*
92+
* @param pos World position.
93+
*
94+
* @return Returns true, if the position is inside the node.
95+
*/
96+
- (BOOL)hitTestWithWorldPos:(CGPoint)pos;
97+
98+
#if ( TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR )
7799

78100
#pragma mark -
79101
#pragma mark Touch Handling Methods

cocos2d/CCResponder.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ - (void)setUserInteractionEnabled:(BOOL)userInteractionEnabled
6464
[[[CCDirector sharedDirector] responderManager] markAsDirty];
6565
}
6666

67+
// -----------------------------------------------------------------
68+
// override for touch and mouse functionality
69+
70+
- (BOOL)hitTestWithWorldPos:(CGPoint)pos
71+
{
72+
return(NO);
73+
}
74+
6775
// -----------------------------------------------------------------
6876
#pragma mark - iOS
6977
// -----------------------------------------------------------------

0 commit comments

Comments
 (0)