Hi, I have a tile map and I try to update touched tile’s opacity.
Here is a code snippet:
void GameLayer::onTouchesEnded (const std::vector& touches, Event* unused_event)
{
auto touch = touches.at( 0 );
auto touchLocation = touch->getLocationInView();
touchLocation = Director::getInstance()->convertToGL( touchLocation );
touchLocation = convertToNodeSpace( touchLocation );
log( "convertToNodeSpace: %f, %f", touchLocation.x, touchLocation.y );
auto tileCoordinate = getTileCoordFromLocation( touchLocation - board->getPosition() );
log( "TOUCHED: %f, %f", tileCoordinate.x, tileCoordinate.y );
auto cell = board->getTileAt( tileCoordinate );
cell->setOpacity( 100 );
}
Point GameLayer::getTileCoordFromLocation (Point location)
{
Point tileCoord;
tileCoord.x = location.x / board->getMapTileSize().width;
tileCoord.y = ((board->getLayerSize().height * board->getMapTileSize().height) - location.y) / board->getMapTileSize().height;
return tileCoord;
}
I actually take this snippets from the forum and tried to adapt them, but it doesn’t work:;qst properly.