使用Cocos2D。我目前已将大部分播放器精灵和行为从调试映射中分类,现在我无法从sprite类引用TMXLayer。我已经尝试从sprite类在此方法中分配DebugZoneLayer类的实例,并以奇怪的结果释放它。这编译没有错误,但无法测试 if(blocksCollidableGID | blocksCollidable2GID){有条件,因为debugZoneLayer.blocksCollidable现在对此方法没有任何意义。
sprite类中的方法:
-(BOOL) checkTileCollisionForStrafing:(NSString*)omit{
for(int j = 0; j < _collisPushPointsNums; j++){
NSValue *val = [_collisPushPoints objectAtIndex:j];
CGPoint p = [val CGPointValue];
CGPoint tileCoord;
if(omit==@"y"){
tileCoord = [debugZoneLayer tileCoordForPosition:ccp(_heroSprite.position.x+_vel.x+p.x, _heroSprite.position.y+(p.y+.001))];
}else{
tileCoord = [debugZoneLayer tileCoordForPosition:ccp(_heroSprite.position.x+p.x, _heroSprite.position.y+_vel.y+p.y)];
}
int blocksCollidableGID = [debugZoneLayer.blocksCollidable tileGIDAt:tileCoord];
int blocksCollidable2GID = [debugZoneLayer.blocksCollidable2 tileGIDAt:tileCoord];
if (blocksCollidableGID | blocksCollidable2GID){
NSLog(@"j = %i", j);
return YES;
}
}
return NO;
}