Skip to content

Commit 2f12530

Browse files
committed
Merge branch 'develop-v3' of github:cocos2d/cocos2d-iphone into develop-v3
Former-commit-id: 190ad09
2 parents 6ddf1cf + 329a512 commit 2f12530

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

cocos2d-ui/CCBReader/CCBAnimationManager.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ - (CCActionInterval*) actionFromKeyframe0:(CCBKeyframe*)kf0 andKeyframe1:(CCBKey
147147
{
148148
return [CCBRotateTo actionWithDuration:duration angle:[kf1.value floatValue]];
149149
}
150-
else if ([name isEqualToString:@"rotationX"])
150+
else if ([name isEqualToString:@"rotationalSkewX"])
151151
{
152152
return [CCBRotateXTo actionWithDuration:duration angle:[kf1.value floatValue]];
153153
}
154-
else if ([name isEqualToString:@"rotationY"])
154+
else if ([name isEqualToString:@"rotationalSkewY"])
155155
{
156156
return [CCBRotateYTo actionWithDuration:duration angle:[kf1.value floatValue]];
157157
}

cocos2d/CCNode.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ -(float) rotation
236236
if(body){
237237
return -CC_RADIANS_TO_DEGREES(body.absoluteRadians) + NodeToPhysicsRotation(self.parent);
238238
} else {
239-
NSAssert( _rotationalSkewX == _rotationalSkewY, @"CCNode#rotation. RotationX != RotationY. Don't know which one to return");
239+
NSAssert( _rotationalSkewX == _rotationalSkewY, @"CCNode#rotation. rotationalSkewX != rotationalSkewY. Don't know which one to return");
240240
return _rotationalSkewX;
241241
}
242242
}

templates/cocos2d iOS.xctemplate/Newton/LightBulb.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ - (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event
6060
- (void)touchMoved:(UITouch *)touch withEvent:(UIEvent *)event
6161
{
6262
// Place the light bulb at the touch position
63-
self.position = touch.locationInWorld;
63+
self.position = [_parent convertToNodeSpace:touch.locationInWorld];
6464
}
6565

6666
// -----------------------------------------------------------------------

templates/cocos2d iOS.xctemplate/Newton/NewtonSphere.m

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@ - (BOOL)hitTestWithWorldPos:(CGPoint)pos
154154

155155
// To fix this, the hit test function is overridden.
156156
// As this is a simple sphere, the hit test will return YES, if the touch distance to sphere, is less than radius
157+
158+
// get the position in the node
159+
CGPoint nodePos = [self convertToNodeSpace:pos];
157160

158-
// calculate distance from touch to node position
159-
float distance = ccpDistance(pos, self.position);
161+
// calculate distance from touch to node center
162+
float distance = ccpLength(nodePos);
160163
return(distance < _sphere.contentSize.width * 0.5);
161164
}
162165

@@ -166,26 +169,34 @@ - (BOOL)hitTestWithWorldPos:(CGPoint)pos
166169

167170
- (void)touchBegan:(UITouch *)touch withEvent:(UIEvent *)event
168171
{
172+
// convert the touch into parents coordinate system
173+
// This is often the same as the world location, but if the scene is ex, scaled or offset, it might not be
174+
CGPoint parentPos = [_parent convertToNodeSpace:touch.locationInWorld];
175+
169176
// The spehre was grabbed.
170177
// To move the sphere around in a "believeable" manner, two things has to be done
171178
// 1) the mass has to be increased, to simulate "an unstopable force" (please dont add an imovable object to the space, or chipmunk will crash ... no it wont :)
172179
self.physicsBody.mass = NewtonSphereMovingMass;
173-
180+
174181
// 2) Save state data, like time and position, so that a velocity can be calculated when moving the sphere.
175182
// Velocity must be set on forced movement, otherwise the collisions will feel "mushy"
176183
_grabbed = YES;
177184
_previousVelocity = CGPointZero;
178185
_previousTime = event.timestamp;
179-
_previousPos = touch.locationInWorld;
186+
_previousPos = parentPos;
180187
CCLOG(@"A Newton Sphere was touched");
181188
}
182189

183190
- (void)touchMoved:(UITouch *)touch withEvent:(UIEvent *)event
184191
{
192+
// convert the touch into parents coordinate system
193+
// This is often the same as the world location, but if the scene is ex, scaled or offset, it might not be
194+
CGPoint parentPos = [_parent convertToNodeSpace:touch.locationInWorld];
195+
185196
// on each move, calculate a velocity used in update, and save new state data
186-
_previousVelocity = ccpMult( ccpSub(touch.locationInWorld, _previousPos), 1 / (event.timestamp - _previousTime));
197+
_previousVelocity = ccpMult( ccpSub(parentPos, _previousPos), 1 / (event.timestamp - _previousTime));
187198
_previousTime = event.timestamp;
188-
_previousPos = touch.locationInWorld;
199+
_previousPos = parentPos;
189200
}
190201

191202
- (void)touchEnded:(UITouch *)touch withEvent:(UIEvent *)event

0 commit comments

Comments
 (0)