本文整理汇总了C++中CCTMXLayer::isVisible方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTMXLayer::isVisible方法的具体用法?C++ CCTMXLayer::isVisible怎么用?C++ CCTMXLayer::isVisible使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCTMXLayer
的用法示例。
在下文中一共展示了CCTMXLayer::isVisible方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ccTouchesBegan
void HelloWorld::ccTouchesBegan(cocos2d::CCSet *pTouches, cocos2d::CCEvent *pEvent)
{
CCNode* node = this->getChildByTag(TileMapNode);
//NSAssert([node isKindOfClass:[CCTMXTiledMap class]], @"not a CCTMXTiledMap");
CCTMXTiledMap* tileMap = (CCTMXTiledMap*)node;
// get the position in tile coordinates from the touch location
CCPoint touchLocation = this->locationFromTouch((cocos2d::CCTouch *)pTouches->anyObject());
CCPoint tilePos = this->tilePosFromLocation(touchLocation, tileMap);
//// move tilemap so that touched tiles is at center of screen
this->centerTileMapOnTileCoord(tilePos, tileMap);
// Check if the touch was on water (eg. tiles with isWater property drawn in GameEventLayer)
bool isTouchOnWater = false;
CCTMXLayer* eventLayer = tileMap->layerNamed("GameEventLayer");
int tileGID = eventLayer->tileGIDAt(tilePos);
//
if (tileGID != 0) {
CCDictionary* properties = tileMap->propertiesForGID(tileGID);
if (properties) {
//CCLOG(@"NSDictionary 'properties' contains:\n%@", properties);
const CCString * isWaterProperty = properties->valueForKey("isWater");
isTouchOnWater = isWaterProperty->boolValue();
}
}
// Check if the touch was within one of the rectangle objects
CCTMXObjectGroup* objectLayer = tileMap->objectGroupNamed("ObjectLayer");
//NSAssert([objectLayer isKindOfClass:[CCTMXObjectGroup class]],
// @"ObjectLayer not found or not a CCTMXObjectGroup");
bool isTouchInRectangle = false;
int numObjects = objectLayer->getObjects()->count();
for (int i = 0; i < numObjects; i++){
CCDictionary* properties = (CCDictionary*)objectLayer->getObjects()->objectAtIndex(i);
CCRect rect = this->getRectFromObjectProperties(properties, tileMap);
//
if (CCRect::CCRectContainsPoint(rect, touchLocation)) {
isTouchInRectangle = true;
break;
}
}
// decide what to do depending on where the touch was ...
if (isTouchOnWater) {
//[[SimpleAudioEngine sharedEngine] playEffect:@"alien-sfx.caf"];
CCLog("touchOnWater");
}
else if (isTouchInRectangle) {
CCLog("touchObject");
CCParticleSystem* system = CCParticleSystemQuad::particleWithFile("fx-explosion.plist");
system->setAutoRemoveOnFinish(true);
system->setPosition(touchLocation);
this->addChild(system, 1);
}
else {
#if 0
// get the winter layer and toggle its visibility
CCTMXLayer* winterLayer = tileMap->layerNamed("WinterLayer");
winterLayer->setVisible(!winterLayer->isVisible());
// other options you might be interested in are:
// remove the touched tile
winterLayer->removeTileAt(tilePos);
// add a specific tile
tileGID = winterLayer->tileGIDAt(CCPointMake(0, 19));
winterLayer->setTileGID(tileGID, tilePos);
#endif
}
}