Skip to content

Commit

Permalink
Implemented position test for centered vertically centered label
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfalk committed Apr 16, 2014
1 parent 81df88b commit bbf3ef3
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions NORLabelNodeTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,26 @@ - (void)testThatSubnodesInheritsPropertiesFromParent{
}


//-(void)testThatVerticallyCenteredNodesCentersOnMiddleOfFrame{
// CGPoint position = CGPointMake(0, 100);
//
// NORLabelNode *threeLineNode = [self nodeWithThreeSubNodes];
// threeLineNode.verticalAlignmentMode = SKLabelVerticalAlignmentModeCenter;
// threeLineNode.position = position;
// SKLabelNode *middleNode = [threeLineNode.subNodes objectAtIndex:1];
//
// SKLabelNode *singleLineNode = [SKLabelNode node];
// singleLineNode.text = @"who swallowed a fly";
// singleLineNode.verticalAlignmentMode = SKLabelVerticalAlignmentModeCenter;
// singleLineNode.position = position;
//
// XCTAssertEqual(singleLineNode.position.y, middleNode.position.y, @"The nodes should have the same y-position");
//}
-(void)testThatVerticallyCenteredNodesCentersOnMiddleOfFrame{
CGPoint position = CGPointMake(0, 100);
SKScene *scene = [SKScene sceneWithSize:[UIApplication sharedApplication].keyWindow.frame.size];

NORLabelNode *threeLineNode = [self nodeWithThreeSubNodes];
threeLineNode.verticalAlignmentMode = SKLabelVerticalAlignmentModeCenter;
threeLineNode.position = position;
[scene addChild:threeLineNode];

SKLabelNode *middleNode = [threeLineNode.subNodes objectAtIndex:1];
CGPoint middleConvertedPosition = [threeLineNode convertPoint:middleNode.position toNode:threeLineNode.parent];

SKLabelNode *singleLineNode = [SKLabelNode node];
singleLineNode.text = @"who swallowed a fly";
singleLineNode.verticalAlignmentMode = SKLabelVerticalAlignmentModeCenter;
singleLineNode.position = position;
[scene addChild:singleLineNode];

XCTAssertEqual(singleLineNode.position.y, middleConvertedPosition.y, @"The nodes should have the same y-position");
}


- (NORLabelNode *)nodeWithThreeSubNodes{
Expand Down

0 comments on commit bbf3ef3

Please sign in to comment.