我正在创建一个游戏,其中行和列中的一定数量的块从屏幕顶部落下并落在地板上。当玩家触摸某种颜色的块时,该块以及相同颜色的相邻块被移除。我的
有问题if ([touchedNode isKindOfClass: [BlockSpriteNode class]]){}
出于某种原因,如果我将此if语句留在其中,则在单击时不会删除块。但是,如果我将其删除或执行
if(YES){}
然后它的工作原理。这是我的方法:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
/* Called when a touch begins */
UITouch * touch = [touches anyObject];
CGPoint location = [touch locationInNode:self];
//ensure that touches are acknowledged and shows where on the screen the touch happened
NSLog(@"Screen has been touched @(%f, %f) ", location.x, location.y);
//get the object that was touched
SKSpriteNode * touchedNode = (SKSpriteNode *) [self nodeAtPoint:location];
//ensure a BlockSpriteNode was touched
if ([touchedNode isKindOfClass: [BlockSpriteNode class]])
{
//debug to check that i hit a block
NSLog(@"you touched a block");
//cast the touched item in BlockSpriteNode
BlockSpriteNode * touchedBlock = (BlockSpriteNode *)touchedNode;
//remove a block from the scene
[touchedBlock removeFromParent];
}
}