Beispiel #1
0
TMXIsoObjectsTestNew::TMXIsoObjectsTestNew()
{
    auto map = cocos2d::experimental::TMXTiledMap::create("TileMaps/iso-test-objectgroup.tmx");
    addChild(map, -1, kTagTileMap);
    
    Size CC_UNUSED s = map->getContentSize();
    CCLOG("ContentSize: %f, %f", s.width,s.height);

    auto group = map->getObjectGroup("Object Group 1");

    auto& objects = group->getObjects();
    
    Value objectsVal = Value(objects);
    CCLOG("%s", objectsVal.getDescription().c_str());
    
    auto drawNode = DrawNode::create();
    Color4F color(1.0, 1.0, 1.0, 1.0);
    for (auto& obj : objects)
    {
        ValueMap& dict = obj.asValueMap();
        
        float x = dict["x"].asFloat();
        float y = dict["y"].asFloat();
        float width = dict["width"].asFloat();
        float height = dict["height"].asFloat();
        
        drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
        drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);
        drawNode->drawLine(Vec2(x + width,y + height), Vec2(x,y + height), color);
        drawNode->drawLine(Vec2(x,y + height), Vec2(x,y), color);
    }
    map->addChild(drawNode, 10);
}
Beispiel #2
0
//------------------------------------------------------------------
//
// TMXGIDObjectsTestNew
//
//------------------------------------------------------------------
TMXGIDObjectsTestNew::TMXGIDObjectsTestNew()
{
    auto map = cocos2d::experimental::TMXTiledMap::create("TileMaps/test-object-layer.tmx");
    addChild(map, -1, kTagTileMap);

    Size CC_UNUSED s = map->getContentSize();
    CCLOG("Contentsize: %f, %f", s.width, s.height);

    CCLOG("----> Iterating over all the group objets");
    
    auto drawNode = DrawNode::create();
    Color4F color(1.0, 1.0, 1.0, 1.0);
    auto group = map->getObjectGroup("Object Layer 1");
    auto objects = group->getObjects();
    for (auto& obj : objects)
    {
        ValueMap& dict = obj.asValueMap();
        
        float x = dict["x"].asFloat();
        float y = dict["y"].asFloat();
        float width = dict["width"].asFloat();
        float height = dict["height"].asFloat();
        
        drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
        drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);
        drawNode->drawLine(Vec2(x + width,y + height), Vec2(x,y + height), color);
        drawNode->drawLine(Vec2(x,y + height), Vec2(x,y), color);
    }
    map->addChild(drawNode, 10);
}
Beispiel #3
0
void TMXIsoObjectsTest::onDraw(const Mat4 &transform, bool transformUpdated)
{
    Director* director = Director::getInstance();
    CCASSERT(nullptr != director, "Director is null when seting matrix stack");
    director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
    director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);

    auto map = (TMXTiledMap*) getChildByTag(kTagTileMap);
    auto pos = map->getPosition();
    auto group = map->getObjectGroup("Object Group 1");

    auto& objects = group->getObjects();
    for (auto& obj : objects)
    {
        ValueMap& dict = obj.asValueMap();
        float x = dict["x"].asFloat();
        float y = dict["y"].asFloat();
        float width = dict["width"].asFloat();
        float height = dict["height"].asFloat();
        
        glLineWidth(3);
        
        DrawPrimitives::drawLine( pos + Vec2(x,y), pos + Vec2(x+width,y) );
        DrawPrimitives::drawLine( pos + Vec2(x+width,y), pos + Vec2(x+width,y+height) );
        DrawPrimitives::drawLine( pos + Vec2(x+width,y+height), pos + Vec2(x,y+height) );
        DrawPrimitives::drawLine( pos + Vec2(x,y+height), pos + Vec2(x,y) );
        
        glLineWidth(1);
    }

    director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
}
void TMXIsoObjectsTest::onDraw()
{
    kmMat4 oldMat;
    kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat);
    kmGLLoadMatrix(&_modelViewTransform);
    
    auto map = (TMXTiledMap*) getChildByTag(kTagTileMap);
    auto group = map->getObjectGroup("Object Group 1");

    auto& objects = group->getObjects();
    for (auto& obj : objects)
    {
        ValueMap& dict = obj.asValueMap();
        float x = dict["x"].asFloat();
        float y = dict["y"].asFloat();
        float width = dict["width"].asFloat();
        float height = dict["height"].asFloat();
        
        glLineWidth(3);
        
        DrawPrimitives::drawLine( Point(x,y), Point(x+width,y) );
        DrawPrimitives::drawLine( Point(x+width,y), Point(x+width,y+height) );
        DrawPrimitives::drawLine( Point(x+width,y+height), Point(x,y+height) );
        DrawPrimitives::drawLine( Point(x,y+height), Point(x,y) );
        
        glLineWidth(1);
    }

    kmGLLoadMatrix(&oldMat);
}
Beispiel #5
0
bool Level::init(std::string levelName, std::string collisionObjectGroupName)
{
	if (!TMXTiledMap::initWithTMXFile(levelName))
	{
		return false;
	}

	_collisionObjectGroup = getObjectGroup(collisionObjectGroupName);

	createPhysicsBody();
	
	return true;
}
Beispiel #6
0
void HelloWorld::createObjectsLayerTest()
{
    auto map = TMXTiledMap::create("ortho-objects.tmx");
    addChild(map, -1, 0);
    
    Size CC_UNUSED s = map->getContentSize();
    CCLOG("ContentSize: %f, %f", s.width,s.height);
    
    auto group = map->getObjectGroup("Object Group 1");
    auto& objects = group->getObjects();
    
    Value objectsVal = Value(objects);
    CCLOG("%s", objectsVal.getDescription().c_str());
}
Beispiel #7
0
//------------------------------------------------------------------
//
// TMXOrthoObjectsTest
//
//------------------------------------------------------------------
TMXOrthoObjectsTest::TMXOrthoObjectsTest()
{
    auto map = TMXTiledMap::create("TileMaps/ortho-objects.tmx");
    addChild(map, -1, kTagTileMap);
    
    Size CC_UNUSED s = map->getContentSize();
    CCLOG("ContentSize: %f, %f", s.width,s.height);
    
    auto group = map->getObjectGroup("Object Group 1");
    auto& objects = group->getObjects();

    Value objectsVal = Value(objects);
    CCLOG("%s", objectsVal.getDescription().c_str());
}