2010-11-18 14:50:28 +08:00
|
|
|
#include "TileMapTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
enum
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
kTagTileMap = 1,
|
2010-11-18 14:50:28 +08:00
|
|
|
};
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* nextTileMapAction();
|
|
|
|
Layer* backTileMapAction();
|
|
|
|
Layer* restartTileMapAction();
|
2011-07-08 15:57:46 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TileMapTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TileMapTest::TileMapTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TileMapAtlas::create(s_TilesPng, s_LevelMapTga, 16, 16);
|
2012-04-19 14:35:52 +08:00
|
|
|
// Convert it to "alias" (GL_LINEAR filtering)
|
|
|
|
map->getTexture()->setAntiAliasTexParameters();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2012-06-11 14:44:32 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// If you are not going to use the Map, you can free it now
|
|
|
|
// NEW since v0.7
|
|
|
|
map->releaseMap();
|
|
|
|
|
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
map->setAnchorPoint( Point(0, 0.5f) );
|
2011-02-23 16:47:25 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto scale = ScaleBy::create(4, 0.8f);
|
|
|
|
auto scaleBack = scale->reverse();
|
2011-05-12 10:52:10 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto seq = Sequence::create(scale, scaleBack, NULL);
|
2011-05-12 10:52:10 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
map->runAction(RepeatForever::create(seq));
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TileMapTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TileMapAtlas";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TileMapEditTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TileMapEditTest::TileMapEditTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TileMapAtlas::create(s_TilesPng, s_LevelMapTga, 16, 16);
|
2012-04-19 14:35:52 +08:00
|
|
|
// Create an Aliased Atlas
|
|
|
|
map->getTexture()->setAliasTexParameters();
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2012-06-11 14:44:32 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// If you are not going to use the Map, you can free it now
|
|
|
|
// [tilemap releaseMap);
|
|
|
|
// And if you are going to use, it you can access the data with:
|
2012-06-11 14:44:32 +08:00
|
|
|
schedule(schedule_selector(TileMapEditTest::updateMap), 0.2f);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
map->setAnchorPoint( Point(0, 0) );
|
|
|
|
map->setPosition( Point(-20,-200) );
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void TileMapEditTest::updateMap(float dt)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// IMPORTANT
|
|
|
|
// The only limitation is that you cannot change an empty, or assign an empty tile to a tile
|
|
|
|
// The value 0 not rendered so don't assign or change a tile with value 0
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto tilemap = (TileMapAtlas*) getChildByTag(kTagTileMap);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// For example you can iterate over all the tiles
|
|
|
|
// using this code, but try to avoid the iteration
|
|
|
|
// over all your tiles in every frame. It's very expensive
|
|
|
|
// for(int x=0; x < tilemap.tgaInfo->width; x++) {
|
|
|
|
// for(int y=0; y < tilemap.tgaInfo->height; y++) {
|
2013-07-12 14:30:26 +08:00
|
|
|
// Color3B c =[tilemap tileAt:Size(x,y));
|
2012-04-19 14:35:52 +08:00
|
|
|
// if( c.r != 0 ) {
|
2013-03-03 10:32:09 +08:00
|
|
|
// ////----CCLOG("%d,%d = %d", x,y,c.r);
|
2012-04-19 14:35:52 +08:00
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// NEW since v0.7
|
2013-07-20 13:01:27 +08:00
|
|
|
Color3B c = tilemap->getTileAt(Point(13,21));
|
2012-04-19 14:35:52 +08:00
|
|
|
c.r++;
|
|
|
|
c.r %= 50;
|
|
|
|
if( c.r==0)
|
|
|
|
c.r=1;
|
|
|
|
|
|
|
|
// NEW since v0.7
|
2013-07-12 14:11:55 +08:00
|
|
|
tilemap->setTile(c, Point(13,21) );
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TileMapEditTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Editable TileMapAtlas";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXOrthoTest::TMXOrthoTest()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
//
|
|
|
|
// Test orthogonal with 3d camera and anti-alias textures
|
|
|
|
//
|
|
|
|
// it should not flicker. No artifacts should appear
|
|
|
|
//
|
2013-08-16 16:05:27 +08:00
|
|
|
//auto color = LayerColor::create( Color4B(64,64,64,255) );
|
2012-04-19 14:35:52 +08:00
|
|
|
//addChild(color, -1);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/orthogonal-test2.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2012-06-11 14:44:32 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-11-29 10:37:40 +08:00
|
|
|
auto& pChildrenArray = map->getChildren();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-11-29 10:37:40 +08:00
|
|
|
pChildrenArray.forEach([](Node* obj){
|
|
|
|
auto child = static_cast<SpriteBatchNode*>(obj);
|
2012-04-19 14:35:52 +08:00
|
|
|
child->getTexture()->setAntiAliasTexParameters();
|
2013-11-29 10:37:40 +08:00
|
|
|
});
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
float x, y, z;
|
2013-09-16 20:38:03 +08:00
|
|
|
map->getCamera()->getEye(&x, &y, &z);
|
|
|
|
map->getCamera()->setEye(x-200, y, z+300);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
void TMXOrthoTest::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
TileDemo::onEnter();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-07-26 04:36:19 +08:00
|
|
|
Director::getInstance()->setProjection(Director::Projection::_3D);
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoTest::onExit()
|
|
|
|
{
|
2013-07-26 04:36:19 +08:00
|
|
|
Director::getInstance()->setProjection(Director::Projection::_2D);
|
2012-04-19 14:35:52 +08:00
|
|
|
TileDemo::onExit();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TMXOrthoTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Orthogonal test";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoTest2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXOrthoTest2::TMXOrthoTest2()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/orthogonal-test1.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-11-29 10:37:40 +08:00
|
|
|
auto& pChildrenArray = map->getChildren();
|
2013-06-20 14:17:10 +08:00
|
|
|
SpriteBatchNode* child = NULL;
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-11-29 10:37:40 +08:00
|
|
|
pChildrenArray.forEach([&child](Node* obj){
|
|
|
|
child = static_cast<SpriteBatchNode*>(obj);
|
2012-04-19 14:35:52 +08:00
|
|
|
child->getTexture()->setAntiAliasTexParameters();
|
2013-11-29 10:37:40 +08:00
|
|
|
});
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
map->runAction( ScaleBy::create(2, 0.5f) ) ;
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TMXOrthoTest2::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Ortho test2";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoTest3
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXOrthoTest3::TMXOrthoTest3()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/orthogonal-test3.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-11-29 10:37:40 +08:00
|
|
|
auto& children = map->getChildren();
|
2013-06-20 14:17:10 +08:00
|
|
|
SpriteBatchNode* child = NULL;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-11-29 10:37:40 +08:00
|
|
|
children.forEach([&child](Node* node){
|
|
|
|
child = static_cast<SpriteBatchNode*>(node);
|
2012-04-19 14:35:52 +08:00
|
|
|
child->getTexture()->setAntiAliasTexParameters();
|
2013-11-29 10:37:40 +08:00
|
|
|
});
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
map->setScale(0.2f);
|
2013-07-12 14:11:55 +08:00
|
|
|
map->setAnchorPoint( Point(0.5f, 0.5f) );
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TMXOrthoTest3::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX anchorPoint test";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoTest4
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXOrthoTest4::TMXOrthoTest4()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/orthogonal-test4.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s1 = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s1.width,s1.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-11-29 10:37:40 +08:00
|
|
|
SpriteBatchNode* child = nullptr;
|
|
|
|
map->getChildren().forEach([&child](Node* node){
|
|
|
|
child = static_cast<SpriteBatchNode*>(node);
|
2012-04-19 14:35:52 +08:00
|
|
|
child->getTexture()->setAntiAliasTexParameters();
|
2013-11-29 10:37:40 +08:00
|
|
|
});
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
map->setAnchorPoint(Point(0, 0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
auto layer = map->getLayer("Layer 0");
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = layer->getLayerSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Sprite* sprite;
|
2013-07-20 13:01:27 +08:00
|
|
|
sprite = layer->getTileAt(Point(0,0));
|
2012-04-19 14:35:52 +08:00
|
|
|
sprite->setScale(2);
|
2013-07-20 13:01:27 +08:00
|
|
|
sprite = layer->getTileAt(Point(s.width-1,0));
|
2012-04-19 14:35:52 +08:00
|
|
|
sprite->setScale(2);
|
2013-07-20 13:01:27 +08:00
|
|
|
sprite = layer->getTileAt(Point(0,s.height-1));
|
2012-04-19 14:35:52 +08:00
|
|
|
sprite->setScale(2);
|
2013-07-20 13:01:27 +08:00
|
|
|
sprite = layer->getTileAt(Point(s.width-1,s.height-1));
|
2012-04-19 14:35:52 +08:00
|
|
|
sprite->setScale(2);
|
|
|
|
|
|
|
|
schedule( schedule_selector(TMXOrthoTest4::removeSprite), 2 );
|
2010-11-18 14:50:28 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void TMXOrthoTest4::removeSprite(float dt)
|
2010-11-18 14:50:28 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
unschedule(schedule_selector(TMXOrthoTest4::removeSprite));
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
auto map = static_cast<TMXTiledMap*>( getChildByTag(kTagTileMap) );
|
|
|
|
auto layer = map->getLayer("Layer 0");
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = layer->getLayerSize();
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto sprite = layer->getTileAt( Point(s.width-1,0) );
|
2012-04-19 14:35:52 +08:00
|
|
|
layer->removeChild(sprite, true);
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoTest4::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX width/height test";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXReadWriteTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
enum
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
SID_UPDATECOL = 100,
|
|
|
|
SID_REPAINTWITHGID,
|
|
|
|
SID_REMOVETILES
|
2010-09-01 17:30:51 +08:00
|
|
|
};
|
|
|
|
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXReadWriteTest::TMXReadWriteTest()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_gid = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/orthogonal-test2.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = map->getLayer("Layer 0");
|
2012-04-19 14:35:52 +08:00
|
|
|
layer->getTexture()->setAntiAliasTexParameters();
|
|
|
|
|
|
|
|
map->setScale( 1 );
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto tile0 = layer->getTileAt(Point(1,63));
|
|
|
|
auto tile1 = layer->getTileAt(Point(2,63));
|
|
|
|
auto tile2 = layer->getTileAt(Point(3,62));//Point(1,62));
|
|
|
|
auto tile3 = layer->getTileAt(Point(2,62));
|
2013-07-12 14:11:55 +08:00
|
|
|
tile0->setAnchorPoint( Point(0.5f, 0.5f) );
|
|
|
|
tile1->setAnchorPoint( Point(0.5f, 0.5f) );
|
|
|
|
tile2->setAnchorPoint( Point(0.5f, 0.5f) );
|
|
|
|
tile3->setAnchorPoint( Point(0.5f, 0.5f) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto move = MoveBy::create(0.5f, Point(0,160));
|
|
|
|
auto rotate = RotateBy::create(2, 360);
|
|
|
|
auto scale = ScaleBy::create(2, 5);
|
|
|
|
auto opacity = FadeOut::create(2);
|
|
|
|
auto fadein = FadeIn::create(2);
|
|
|
|
auto scaleback = ScaleTo::create(1, 1);
|
|
|
|
auto finish = CallFuncN::create(CC_CALLBACK_1(TMXReadWriteTest::removeSprite, this));
|
|
|
|
auto seq0 = Sequence::create(move, rotate, scale, opacity, fadein, scaleback, finish, NULL);
|
|
|
|
auto seq1 = seq0->clone();
|
|
|
|
auto seq2 = seq0->clone();
|
|
|
|
auto seq3 = seq0->clone();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
tile0->runAction(seq0);
|
|
|
|
tile1->runAction(seq1);
|
|
|
|
tile2->runAction(seq2);
|
|
|
|
tile3->runAction(seq3);
|
|
|
|
|
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
_gid = layer->getTileGIDAt(Point(0,63));
|
2013-06-15 14:03:30 +08:00
|
|
|
////----CCLOG("Tile GID at:(0,63) is: %d", _gid);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
schedule(schedule_selector(TMXReadWriteTest::updateCol), 2.0f);
|
2012-11-19 16:28:37 +08:00
|
|
|
schedule(schedule_selector(TMXReadWriteTest::repaintWithGID), 2.05f);
|
2012-04-19 14:35:52 +08:00
|
|
|
schedule(schedule_selector(TMXReadWriteTest::removeTiles), 1.0f);
|
|
|
|
|
2013-03-03 10:32:09 +08:00
|
|
|
////----CCLOG("++++atlas quantity: %d", layer->textureAtlas()->getTotalQuads());
|
|
|
|
////----CCLOG("++++children: %d", layer->getChildren()->count() );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_gid2 = 0;
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
void TMXReadWriteTest::removeSprite(Node* sender)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2013-03-03 10:32:09 +08:00
|
|
|
////----CCLOG("removing tile: %x", sender);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto p = ((Node*)sender)->getParent();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
if (p)
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
p->removeChild((Node*)sender, true);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-03-03 10:32:09 +08:00
|
|
|
//////----CCLOG("atlas quantity: %d", p->textureAtlas()->totalQuads());
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void TMXReadWriteTest::updateCol(float dt)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = (TMXTiledMap*)getChildByTag(kTagTileMap);
|
|
|
|
auto layer = (TMXLayer*)map->getChildByTag(0);
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-03-03 10:32:09 +08:00
|
|
|
////----CCLOG("++++atlas quantity: %d", layer->textureAtlas()->getTotalQuads());
|
|
|
|
////----CCLOG("++++children: %d", layer->getChildren()->count() );
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = layer->getLayerSize();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for( int y=0; y< s.height; y++ )
|
|
|
|
{
|
2013-07-12 14:11:55 +08:00
|
|
|
layer->setTileGID(_gid2, Point((float)3, (float)y));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_gid2 = (_gid2 + 1) % 80;
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void TMXReadWriteTest::repaintWithGID(float dt)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// unschedule:_cmd);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = (TMXTiledMap*)getChildByTag(kTagTileMap);
|
|
|
|
auto layer = (TMXLayer*)map->getChildByTag(0);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = layer->getLayerSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
for( int x=0; x<s.width;x++)
|
|
|
|
{
|
|
|
|
int y = (int)s.height-1;
|
2013-07-20 13:01:27 +08:00
|
|
|
unsigned int tmpgid = layer->getTileGIDAt( Point((float)x, (float)y) );
|
2013-07-12 14:11:55 +08:00
|
|
|
layer->setTileGID(tmpgid+1, Point((float)x, (float)y));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void TMXReadWriteTest::removeTiles(float dt)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
unschedule(schedule_selector(TMXReadWriteTest::removeTiles));
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = (TMXTiledMap*)getChildByTag(kTagTileMap);
|
|
|
|
auto layer = (TMXLayer*)map->getChildByTag(0);
|
|
|
|
auto s = layer->getLayerSize();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
for( int y=0; y< s.height; y++ )
|
|
|
|
{
|
2013-07-12 14:11:55 +08:00
|
|
|
layer->removeTileAt( Point(5.0, (float)y) );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string TMXReadWriteTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Read/Write test";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXHexTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXHexTest::TMXHexTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto color = LayerColor::create( Color4B(64,64,64,255) );
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(color, -1);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/hexa-test.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TMXHexTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Hex tes";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXIsoTest::TMXIsoTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto color = LayerColor::create( Color4B(64,64,64,255) );
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(color, -1);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/iso-test.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
// move map to the center of the screen
|
2013-08-16 16:05:27 +08:00
|
|
|
auto ms = map->getMapSize();
|
|
|
|
auto ts = map->getTileSize();
|
2013-07-12 14:11:55 +08:00
|
|
|
map->runAction( MoveTo::create(1.0f, Point( -ms.width * ts.width/2, -ms.height * ts.height/2 )) );
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TMXIsoTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Isometric test 0";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoTest1
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXIsoTest1::TMXIsoTest1()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto color = LayerColor::create( Color4B(64,64,64,255) );
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(color, -1);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/iso-test1.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
map->setAnchorPoint(Point(0.5f, 0.5f));
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TMXIsoTest1::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Isometric test + anchorPoint";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoTest2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXIsoTest2::TMXIsoTest2()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto color = LayerColor::create( Color4B(64,64,64,255) );
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(color, -1);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/iso-test2.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// move map to the center of the screen
|
2013-08-16 16:05:27 +08:00
|
|
|
auto ms = map->getMapSize();
|
|
|
|
auto ts = map->getTileSize();
|
2013-07-12 14:11:55 +08:00
|
|
|
map->runAction( MoveTo::create(1.0f, Point( -ms.width * ts.width/2, -ms.height * ts.height/2 ) ));
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TMXIsoTest2::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Isometric test 2";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXUncompressedTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXUncompressedTest::TMXUncompressedTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto color = LayerColor::create( Color4B(64,64,64,255) );
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(color, -1);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/iso-test2-uncompressed.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// move map to the center of the screen
|
2013-08-16 16:05:27 +08:00
|
|
|
auto ms = map->getMapSize();
|
|
|
|
auto ts = map->getTileSize();
|
2013-07-12 14:11:55 +08:00
|
|
|
map->runAction(MoveTo::create(1.0f, Point( -ms.width * ts.width/2, -ms.height * ts.height/2 ) ));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// testing release map
|
2013-06-20 14:17:10 +08:00
|
|
|
TMXLayer* layer;
|
2013-11-29 10:37:40 +08:00
|
|
|
map->getChildren().forEach([&layer](Node* node){
|
|
|
|
layer= static_cast<TMXLayer*>(node);
|
2012-04-19 14:35:52 +08:00
|
|
|
layer->releaseMap();
|
2013-11-29 10:37:40 +08:00
|
|
|
});
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TMXUncompressedTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Uncompressed test";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXTilesetTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXTilesetTest::TMXTilesetTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/orthogonal-test5.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
TMXLayer* layer;
|
2013-07-24 06:20:22 +08:00
|
|
|
layer = map->getLayer("Layer 0");
|
2012-04-19 14:35:52 +08:00
|
|
|
layer->getTexture()->setAntiAliasTexParameters();
|
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
layer = map->getLayer("Layer 1");
|
2012-04-19 14:35:52 +08:00
|
|
|
layer->getTexture()->setAntiAliasTexParameters();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
layer = map->getLayer("Layer 2");
|
2012-04-19 14:35:52 +08:00
|
|
|
layer->getTexture()->setAntiAliasTexParameters();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
|
|
|
std::string TMXTilesetTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Tileset test";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoObjectsTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXOrthoObjectsTest::TMXOrthoObjectsTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/ortho-objects.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, -1, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-03-03 10:32:09 +08:00
|
|
|
////----CCLOG("----> Iterating over all the group objets");
|
2013-07-24 06:20:22 +08:00
|
|
|
auto group = map->getObjectGroup("Object Group 1");
|
2013-12-03 14:47:35 +08:00
|
|
|
auto& objects = group->getObjects();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-03 14:47:35 +08:00
|
|
|
for (auto& obj : objects)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-04 17:46:57 +08:00
|
|
|
ValueMap& dict = obj.asValueMap();
|
2013-03-03 10:32:09 +08:00
|
|
|
////----CCLOG("object: %x", dict);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-03-03 10:32:09 +08:00
|
|
|
////----CCLOG("----> Fetching 1 object by name");
|
2013-08-16 16:05:27 +08:00
|
|
|
// auto platform = group->objectNamed("platform");
|
2013-03-03 10:32:09 +08:00
|
|
|
////----CCLOG("platform: %x", platform);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoObjectsTest::draw()
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
auto map = static_cast<TMXTiledMap*>( getChildByTag(kTagTileMap) );
|
|
|
|
auto group = map->getObjectGroup("Object Group 1");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-03 14:47:35 +08:00
|
|
|
auto& objects = group->getObjects();
|
|
|
|
|
|
|
|
for (auto& obj : objects)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-04 17:46:57 +08:00
|
|
|
ValueMap& dict = obj.asValueMap();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-03 14:47:35 +08:00
|
|
|
float x = dict["x"].asFloat();
|
|
|
|
float y = dict["y"].asFloat();
|
|
|
|
float width = dict["width"].asFloat();
|
|
|
|
float height = dict["height"].asFloat();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
glLineWidth(3);
|
|
|
|
|
2013-12-03 14:47:35 +08:00
|
|
|
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) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
glLineWidth(1);
|
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoObjectsTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Ortho object test";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoObjectsTest::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "You should see a white box around the 3 platforms";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoObjectsTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
|
|
|
|
TMXIsoObjectsTest::TMXIsoObjectsTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/iso-test-objectgroup.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, -1, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto group = map->getObjectGroup("Object Group 1");
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
//auto objects = group->objects();
|
2013-12-03 14:47:35 +08:00
|
|
|
auto& objects = group->getObjects();
|
2012-04-19 14:35:52 +08:00
|
|
|
//UxMutableDictionary<std::string>* dict;
|
2013-12-03 14:47:35 +08:00
|
|
|
for (auto& obj : objects)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-04 17:46:57 +08:00
|
|
|
ValueMap& dict = obj.asValueMap();
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2013-03-03 10:32:09 +08:00
|
|
|
////----CCLOG("object: %x", dict);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXIsoObjectsTest::draw()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = (TMXTiledMap*) getChildByTag(kTagTileMap);
|
|
|
|
auto group = map->getObjectGroup("Object Group 1");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-03 14:47:35 +08:00
|
|
|
auto& objects = group->getObjects();
|
|
|
|
for (auto& obj : objects)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-04 17:46:57 +08:00
|
|
|
ValueMap& dict = obj.asValueMap();
|
2013-12-03 14:47:35 +08:00
|
|
|
float x = dict["x"].asFloat();
|
|
|
|
float y = dict["y"].asFloat();
|
|
|
|
float width = dict["width"].asFloat();
|
|
|
|
float height = dict["height"].asFloat();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
glLineWidth(3);
|
|
|
|
|
2013-07-26 05:49:43 +08:00
|
|
|
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) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
glLineWidth(1);
|
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoObjectsTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Iso object test";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoObjectsTest::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "You need to parse them manually. See bug #810";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXResizeTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
|
|
|
|
TMXResizeTest::TMXResizeTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/orthogonal-test5.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
TMXLayer* layer;
|
2013-07-24 06:20:22 +08:00
|
|
|
layer = map->getLayer("Layer 0");
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto ls = layer->getLayerSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
for (unsigned int y = 0; y < ls.height; y++)
|
|
|
|
{
|
|
|
|
for (unsigned int x = 0; x < ls.width; x++)
|
|
|
|
{
|
2013-07-12 14:11:55 +08:00
|
|
|
layer->setTileGID(1, Point( x, y ) );
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXResizeTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX resize test";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXResizeTest::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Should not crash. Testing issue #740";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoZorder
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXIsoZorder::TMXIsoZorder()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/iso-test-zorder.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2011-02-23 16:47:25 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = map->getContentSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2013-07-12 14:11:55 +08:00
|
|
|
map->setPosition(Point(-s.width/2,0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
_tamara = Sprite::create(s_pathSister1);
|
2013-12-05 10:35:10 +08:00
|
|
|
map->addChild(_tamara, map->getChildren().size() );
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
int mapWidth = map->getMapSize().width * map->getTileSize().width;
|
2013-07-12 14:11:55 +08:00
|
|
|
_tamara->setPosition(CC_POINT_PIXELS_TO_POINTS(Point( mapWidth/2,0)));
|
|
|
|
_tamara->setAnchorPoint(Point(0.5f,0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto move = MoveBy::create(10, Point(300,250));
|
|
|
|
auto back = move->reverse();
|
|
|
|
auto seq = Sequence::create(move, back,NULL);
|
2013-06-20 14:17:10 +08:00
|
|
|
_tamara->runAction( RepeatForever::create(seq) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
schedule( schedule_selector(TMXIsoZorder::repositionSprite) );
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TMXIsoZorder::~TMXIsoZorder()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->release();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXIsoZorder::onExit()
|
|
|
|
{
|
|
|
|
unschedule(schedule_selector(TMXIsoZorder::repositionSprite));
|
2012-04-19 14:35:52 +08:00
|
|
|
TileDemo::onExit();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void TMXIsoZorder::repositionSprite(float dt)
|
2010-11-18 14:50:28 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto p = _tamara->getPosition();
|
2012-04-19 14:35:52 +08:00
|
|
|
p = CC_POINT_POINTS_TO_PIXELS(p);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = getChildByTag(kTagTileMap);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// there are only 4 layers. (grass and 3 trees layers)
|
|
|
|
// if tamara < 48, z=4
|
|
|
|
// if tamara < 96, z=3
|
|
|
|
// if tamara < 144,z=2
|
|
|
|
|
|
|
|
int newZ = 4 - (p.y / 48);
|
|
|
|
newZ = max(newZ,0);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
map->reorderChild(_tamara, newZ);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoZorder::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Iso Zorder";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoZorder::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Sprite should hide behind the trees";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoZorder
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXOrthoZorder::TMXOrthoZorder()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/orthogonal-test-zorder.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-24 06:20:22 +08:00
|
|
|
_tamara = Sprite::create(s_pathSister1);
|
2013-12-05 10:35:10 +08:00
|
|
|
map->addChild(_tamara, map->getChildren().size());
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->retain();
|
2013-07-12 14:11:55 +08:00
|
|
|
_tamara->setAnchorPoint(Point(0.5f,0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto move = MoveBy::create(10, Point(400,450));
|
|
|
|
auto back = move->reverse();
|
|
|
|
auto seq = Sequence::create(move, back,NULL);
|
2013-06-20 14:17:10 +08:00
|
|
|
_tamara->runAction( RepeatForever::create(seq));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
schedule( schedule_selector(TMXOrthoZorder::repositionSprite));
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TMXOrthoZorder::~TMXOrthoZorder()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->release();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void TMXOrthoZorder::repositionSprite(float dt)
|
2010-11-18 14:50:28 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto p = _tamara->getPosition();
|
2012-04-19 14:35:52 +08:00
|
|
|
p = CC_POINT_POINTS_TO_PIXELS(p);
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = getChildByTag(kTagTileMap);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// there are only 4 layers. (grass and 3 trees layers)
|
|
|
|
// if tamara < 81, z=4
|
|
|
|
// if tamara < 162, z=3
|
|
|
|
// if tamara < 243,z=2
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// -10: customization for this particular sample
|
|
|
|
int newZ = 4 - ( (p.y-10) / 81);
|
|
|
|
newZ = max(newZ,0);
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
map->reorderChild(_tamara, newZ);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoZorder::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Ortho Zorder";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoZorder::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Sprite should hide behind the trees";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoVertexZ
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXIsoVertexZ::TMXIsoVertexZ()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/iso-test-vertexz.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = map->getContentSize();
|
2013-07-12 14:11:55 +08:00
|
|
|
map->setPosition( Point(-s.width/2,0) );
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
|
|
|
|
|
|
|
// because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you
|
2013-06-20 14:17:10 +08:00
|
|
|
// can use any Sprite and it will work OK.
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = map->getLayer("Trees");
|
2013-07-20 13:01:27 +08:00
|
|
|
_tamara = layer->getTileAt( Point(29,29) );
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto move = MoveBy::create(10, Point(300,250) * (1/CC_CONTENT_SCALE_FACTOR()));
|
|
|
|
auto back = move->reverse();
|
|
|
|
auto seq = Sequence::create(move, back,NULL);
|
2013-06-20 14:17:10 +08:00
|
|
|
_tamara->runAction( RepeatForever::create(seq) );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
schedule( schedule_selector(TMXIsoVertexZ::repositionSprite));
|
|
|
|
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TMXIsoVertexZ::~TMXIsoVertexZ()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->release();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void TMXIsoVertexZ::repositionSprite(float dt)
|
2010-11-18 14:50:28 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// tile height is 64x32
|
|
|
|
// map size: 30x30
|
2013-08-16 16:05:27 +08:00
|
|
|
auto p = _tamara->getPosition();
|
2012-04-19 14:35:52 +08:00
|
|
|
p = CC_POINT_POINTS_TO_PIXELS(p);
|
|
|
|
float newZ = -(p.y+32) /16;
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->setVertexZ( newZ );
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXIsoVertexZ::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
TileDemo::onEnter();
|
|
|
|
|
|
|
|
// TIP: 2d projection should be used
|
2013-07-26 04:36:19 +08:00
|
|
|
Director::getInstance()->setProjection(Director::Projection::_2D);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXIsoVertexZ::onExit()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// At exit use any other projection.
|
2013-07-26 04:36:19 +08:00
|
|
|
// Director::getInstance()->setProjection:Director::Projection::_3D);
|
2012-04-19 14:35:52 +08:00
|
|
|
TileDemo::onExit();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoVertexZ::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Iso VertexZ";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoVertexZ::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Sprite should hide behind the trees";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoVertexZ
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXOrthoVertexZ::TMXOrthoVertexZ()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/orthogonal-test-vertexz.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you
|
2013-06-20 14:17:10 +08:00
|
|
|
// can use any Sprite and it will work OK.
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = map->getLayer("trees");
|
2013-07-20 13:01:27 +08:00
|
|
|
_tamara = layer->getTileAt(Point(0,11));
|
2013-06-15 14:03:30 +08:00
|
|
|
CCLOG("%p vertexZ: %f", _tamara, _tamara->getVertexZ());
|
|
|
|
_tamara->retain();
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto move = MoveBy::create(10, Point(400,450) * (1/CC_CONTENT_SCALE_FACTOR()));
|
|
|
|
auto back = move->reverse();
|
|
|
|
auto seq = Sequence::create(move, back,NULL);
|
2013-06-20 14:17:10 +08:00
|
|
|
_tamara->runAction( RepeatForever::create(seq));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
schedule(schedule_selector(TMXOrthoVertexZ::repositionSprite));
|
|
|
|
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TMXOrthoVertexZ::~TMXOrthoVertexZ()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->release();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void TMXOrthoVertexZ::repositionSprite(float dt)
|
2010-11-18 14:50:28 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// tile height is 101x81
|
|
|
|
// map size: 12x12
|
2013-08-16 16:05:27 +08:00
|
|
|
auto p = _tamara->getPosition();
|
2012-04-19 14:35:52 +08:00
|
|
|
p = CC_POINT_POINTS_TO_PIXELS(p);
|
2013-06-15 14:03:30 +08:00
|
|
|
_tamara->setVertexZ( -( (p.y+81) /81) );
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoVertexZ::onEnter()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
TileDemo::onEnter();
|
|
|
|
|
|
|
|
// TIP: 2d projection should be used
|
2013-07-26 04:36:19 +08:00
|
|
|
Director::getInstance()->setProjection(Director::Projection::_2D);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoVertexZ::onExit()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// At exit use any other projection.
|
2013-07-26 04:36:19 +08:00
|
|
|
// Director::getInstance()->setProjection:Director::Projection::_3D);
|
2012-04-19 14:35:52 +08:00
|
|
|
TileDemo::onExit();
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoVertexZ::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Ortho vertexZ";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoVertexZ::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Sprite should hide behind the trees";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoMoveLayer
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXIsoMoveLayer::TMXIsoMoveLayer()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/iso-test-movelayer.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
map->setPosition(Point(-700,-50));
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoMoveLayer::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Iso Move Layer";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoMoveLayer::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Trees should be horizontally aligned";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoMoveLayer
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
TMXOrthoMoveLayer::TMXOrthoMoveLayer()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/orthogonal-test-movelayer.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-03-03 10:32:09 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s.width,s.height);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoMoveLayer::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX Ortho Move Layer";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoMoveLayer::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Trees should be horizontally aligned";
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
2012-03-26 16:46:23 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXTilePropertyTest
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2012-04-08 14:16:29 +08:00
|
|
|
|
|
|
|
TMXTilePropertyTest::TMXTilePropertyTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/ortho-tile-property.tmx");
|
2012-04-08 14:16:29 +08:00
|
|
|
addChild(map ,0 ,kTagTileMap);
|
|
|
|
|
|
|
|
for(int i=1;i<=20;i++){
|
2013-12-03 14:47:35 +08:00
|
|
|
log("GID:%i, Properties:%s", i, map->getPropertiesForGID(i).asString().c_str());
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:46:23 +08:00
|
|
|
std::string TMXTilePropertyTest::title()
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
|
|
|
return "TMX Tile Property Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXTilePropertyTest::subtitle()
|
|
|
|
{
|
|
|
|
return "In the console you should see tile properties";
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:46:23 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoFlipTest
|
|
|
|
//
|
2012-04-08 14:16:29 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
TMXOrthoFlipTest::TMXOrthoFlipTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/ortho-rotation-test.tmx");
|
2012-04-08 14:16:29 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("ContentSize: %f, %f", s.width,s.height);
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-11-29 10:37:40 +08:00
|
|
|
map->getChildren().forEach([](Node* node){
|
|
|
|
auto child = static_cast<SpriteBatchNode*>(node);
|
2012-04-08 14:16:29 +08:00
|
|
|
child->getTexture()->setAntiAliasTexParameters();
|
2013-11-29 10:37:40 +08:00
|
|
|
});
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action = ScaleBy::create(2, 0.5f);
|
2012-04-08 14:16:29 +08:00
|
|
|
map->runAction(action);
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:46:23 +08:00
|
|
|
std::string TMXOrthoFlipTest::title()
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
|
|
|
return "TMX tile flip test";
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:46:23 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoFlipRunTimeTest
|
|
|
|
//
|
2012-04-08 14:16:29 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
TMXOrthoFlipRunTimeTest::TMXOrthoFlipRunTimeTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/ortho-rotation-test.tmx");
|
2012-04-08 14:16:29 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = map->getContentSize();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("ContentSize: %f, %f", s.width,s.height);
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-11-29 10:37:40 +08:00
|
|
|
map->getChildren().forEach([](Node* node){
|
|
|
|
auto child = static_cast<SpriteBatchNode*>(node);
|
2012-04-08 14:16:29 +08:00
|
|
|
child->getTexture()->setAntiAliasTexParameters();
|
2013-11-29 10:37:40 +08:00
|
|
|
});
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action = ScaleBy::create(2, 0.5f);
|
2012-04-08 14:16:29 +08:00
|
|
|
map->runAction(action);
|
|
|
|
|
|
|
|
schedule(schedule_selector(TMXOrthoFlipRunTimeTest::flipIt), 1.0f);
|
|
|
|
}
|
|
|
|
|
2012-03-26 16:46:23 +08:00
|
|
|
std::string TMXOrthoFlipRunTimeTest::title()
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
|
|
|
return "TMX tile flip run time test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoFlipRunTimeTest::subtitle()
|
|
|
|
{
|
|
|
|
return "in 2 sec bottom left tiles will flip";
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void TMXOrthoFlipRunTimeTest::flipIt(float dt)
|
2012-04-08 14:16:29 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = (TMXTiledMap*) getChildByTag(kTagTileMap);
|
|
|
|
auto layer = map->getLayer("Layer 0");
|
2012-04-08 14:16:29 +08:00
|
|
|
|
|
|
|
//blue diamond
|
2013-08-16 16:05:27 +08:00
|
|
|
auto tileCoord = Point(1,10);
|
2012-04-08 14:16:29 +08:00
|
|
|
int flags;
|
2013-07-20 13:01:27 +08:00
|
|
|
unsigned int GID = layer->getTileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
|
2012-04-08 14:16:29 +08:00
|
|
|
// Vertical
|
2013-06-20 14:17:10 +08:00
|
|
|
if( flags & kTMXTileVerticalFlag )
|
|
|
|
flags &= ~kTMXTileVerticalFlag;
|
2012-04-08 14:16:29 +08:00
|
|
|
else
|
2013-06-20 14:17:10 +08:00
|
|
|
flags |= kTMXTileVerticalFlag;
|
2012-04-08 14:16:29 +08:00
|
|
|
layer->setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags);
|
|
|
|
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
tileCoord = Point(1,8);
|
2013-07-20 13:01:27 +08:00
|
|
|
GID = layer->getTileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
|
2012-04-08 14:16:29 +08:00
|
|
|
// Vertical
|
2013-06-20 14:17:10 +08:00
|
|
|
if( flags & kTMXTileVerticalFlag )
|
|
|
|
flags &= ~kTMXTileVerticalFlag;
|
2012-04-08 14:16:29 +08:00
|
|
|
else
|
2013-06-20 14:17:10 +08:00
|
|
|
flags |= kTMXTileVerticalFlag;
|
2012-04-08 14:16:29 +08:00
|
|
|
layer->setTileGID(GID ,tileCoord, (ccTMXTileFlags)flags);
|
|
|
|
|
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
tileCoord = Point(2,8);
|
2013-07-20 13:01:27 +08:00
|
|
|
GID = layer->getTileGIDAt(tileCoord, (ccTMXTileFlags*)&flags);
|
2012-04-08 14:16:29 +08:00
|
|
|
// Horizontal
|
2013-06-20 14:17:10 +08:00
|
|
|
if( flags & kTMXTileHorizontalFlag )
|
|
|
|
flags &= ~kTMXTileHorizontalFlag;
|
2012-04-08 14:16:29 +08:00
|
|
|
else
|
2013-06-20 14:17:10 +08:00
|
|
|
flags |= kTMXTileHorizontalFlag;
|
2012-04-19 14:35:52 +08:00
|
|
|
layer->setTileGID(GID, tileCoord, (ccTMXTileFlags)flags);
|
2012-04-08 14:16:29 +08:00
|
|
|
}
|
2012-03-26 16:46:23 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoFromXMLTest
|
|
|
|
//
|
2012-04-08 14:16:29 +08:00
|
|
|
//------------------------------------------------------------------
|
2012-03-26 16:46:23 +08:00
|
|
|
|
|
|
|
TMXOrthoFromXMLTest::TMXOrthoFromXMLTest()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
string resources = "TileMaps"; // partial paths are OK as resource paths.
|
2012-04-08 14:16:29 +08:00
|
|
|
string file = resources + "/orthogonal-test1.tmx";
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto str = String::createWithContentsOfFile(FileUtils::getInstance()->fullPathForFilename(file.c_str()).c_str());
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(str != NULL, "Unable to open file");
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::createWithXML(str->getCString() ,resources.c_str());
|
2012-04-08 14:16:29 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = map->getContentSize();
|
2013-07-24 06:20:22 +08:00
|
|
|
log("ContentSize: %f, %f", s.width,s.height);
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-11-29 10:37:40 +08:00
|
|
|
map->getChildren().forEach([](Node* node){
|
|
|
|
auto child = static_cast<SpriteBatchNode*>(node);
|
2012-04-08 14:16:29 +08:00
|
|
|
child->getTexture()->setAntiAliasTexParameters();
|
2013-11-29 10:37:40 +08:00
|
|
|
});
|
2012-04-08 14:16:29 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto action = ScaleBy::create(2, 0.5f);
|
2012-03-26 16:46:23 +08:00
|
|
|
map->runAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoFromXMLTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX created from XML test";
|
2012-03-26 16:46:23 +08:00
|
|
|
}
|
|
|
|
|
2011-02-23 16:47:25 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXBug987
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2011-05-12 10:52:10 +08:00
|
|
|
TMXBug987::TMXBug987()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/orthogonal-test6.tmx");
|
2011-05-12 10:52:10 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s1 = map->getContentSize();
|
2011-05-12 10:52:10 +08:00
|
|
|
CCLOG("ContentSize: %f, %f", s1.width,s1.height);
|
|
|
|
|
2013-11-29 10:37:40 +08:00
|
|
|
map->getChildren().forEach([](Node* child){
|
|
|
|
auto node = static_cast<TMXLayer*>(child);
|
2013-07-23 08:25:44 +08:00
|
|
|
node->getTexture()->setAntiAliasTexParameters();
|
2013-11-29 10:37:40 +08:00
|
|
|
});
|
2011-05-12 10:52:10 +08:00
|
|
|
|
2013-07-12 14:11:55 +08:00
|
|
|
map->setAnchorPoint(Point(0, 0));
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = map->getLayer("Tile Layer 1");
|
2013-07-12 14:11:55 +08:00
|
|
|
layer->setTileGID(3, Point(2,2));
|
2011-05-12 10:52:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXBug987::title()
|
|
|
|
{
|
|
|
|
return "TMX Bug 987";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXBug987::subtitle()
|
|
|
|
{
|
|
|
|
return "You should see an square";
|
|
|
|
}
|
|
|
|
|
2011-02-23 16:47:25 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXBug787
|
|
|
|
//
|
2011-05-12 10:52:10 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXBug787::TMXBug787()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/iso-test-bug787.tmx");
|
2011-05-12 10:52:10 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
map->setScale(0.25f);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXBug787::title()
|
|
|
|
{
|
|
|
|
return "TMX Bug 787";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXBug787::subtitle()
|
|
|
|
{
|
|
|
|
return "You should see a map";
|
|
|
|
}
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TileDemo
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
enum
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
IDC_NEXT = 100,
|
|
|
|
IDC_BACK,
|
|
|
|
IDC_RESTART
|
2010-09-01 17:30:51 +08:00
|
|
|
};
|
2010-11-18 14:50:28 +08:00
|
|
|
|
|
|
|
static int sceneIdx = -1;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
#define MAX_LAYER 28
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
Layer* createTileMalayer(int nIndex)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
switch(nIndex)
|
|
|
|
{
|
|
|
|
case 0: return new TMXIsoZorder();
|
|
|
|
case 1: return new TMXOrthoZorder();
|
|
|
|
case 2: return new TMXIsoVertexZ();
|
|
|
|
case 3: return new TMXOrthoVertexZ();
|
|
|
|
case 4: return new TMXOrthoTest();
|
|
|
|
case 5: return new TMXOrthoTest2();
|
|
|
|
case 6: return new TMXOrthoTest3();
|
|
|
|
case 7: return new TMXOrthoTest4();
|
|
|
|
case 8: return new TMXIsoTest();
|
|
|
|
case 9: return new TMXIsoTest1();
|
|
|
|
case 10: return new TMXIsoTest2();
|
|
|
|
case 11: return new TMXUncompressedTest ();
|
|
|
|
case 12: return new TMXHexTest();
|
|
|
|
case 13: return new TMXReadWriteTest();
|
|
|
|
case 14: return new TMXTilesetTest();
|
|
|
|
case 15: return new TMXOrthoObjectsTest();
|
|
|
|
case 16: return new TMXIsoObjectsTest();
|
|
|
|
case 17: return new TMXResizeTest();
|
|
|
|
case 18: return new TMXIsoMoveLayer();
|
|
|
|
case 19: return new TMXOrthoMoveLayer();
|
2012-04-08 14:16:29 +08:00
|
|
|
case 20: return new TMXOrthoFlipTest();
|
|
|
|
case 21: return new TMXOrthoFlipRunTimeTest();
|
2012-03-26 16:46:23 +08:00
|
|
|
case 22: return new TMXOrthoFromXMLTest();
|
2012-04-19 14:35:52 +08:00
|
|
|
case 23: return new TileMapTest();
|
|
|
|
case 24: return new TileMapEditTest();
|
2012-03-26 16:46:23 +08:00
|
|
|
case 25: return new TMXBug987();
|
|
|
|
case 26: return new TMXBug787();
|
2012-04-19 14:35:52 +08:00
|
|
|
case 27: return new TMXGIDObjectsTest();
|
|
|
|
}
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return NULL;
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* nextTileMapAction()
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx++;
|
|
|
|
sceneIdx = sceneIdx % MAX_LAYER;
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = createTileMalayer(sceneIdx);
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->autorelease();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* backTileMapAction()
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
sceneIdx--;
|
|
|
|
int total = MAX_LAYER;
|
|
|
|
if( sceneIdx < 0 )
|
|
|
|
sceneIdx += total;
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = createTileMalayer(sceneIdx);
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->autorelease();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer* restartTileMapAction()
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = createTileMalayer(sceneIdx);
|
2013-07-23 08:25:44 +08:00
|
|
|
layer->autorelease();
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
return layer;
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TileDemo::TileDemo(void)
|
2013-06-08 08:21:11 +08:00
|
|
|
: BaseTest()
|
2010-11-18 14:50:28 +08:00
|
|
|
{
|
2013-10-23 16:14:03 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesMoved = CC_CALLBACK_2(TileDemo::onTouchesMoved, this);
|
2013-10-26 15:04:01 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TileDemo::~TileDemo(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-01 17:30:51 +08:00
|
|
|
std::string TileDemo::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "No title";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TileDemo::subtitle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "drag the screen";
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileDemo::onEnter()
|
|
|
|
{
|
2013-06-08 08:21:11 +08:00
|
|
|
BaseTest::onEnter();
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void TileDemo::restartCallback(Object* sender)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new TileMapTestScene();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild(restartTileMapAction());
|
2010-09-01 17:30:51 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2012-04-19 14:35:52 +08:00
|
|
|
s->release();
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void TileDemo::nextCallback(Object* sender)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new TileMapTestScene();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild( nextTileMapAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2012-04-19 14:35:52 +08:00
|
|
|
s->release();
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
void TileDemo::backCallback(Object* sender)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = new TileMapTestScene();
|
2012-04-19 14:35:52 +08:00
|
|
|
s->addChild( backTileMapAction() );
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(s);
|
2012-04-19 14:35:52 +08:00
|
|
|
s->release();
|
2010-09-01 17:30:51 +08:00
|
|
|
}
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2013-09-03 18:22:03 +08:00
|
|
|
void TileDemo::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
|
2010-09-01 17:30:51 +08:00
|
|
|
{
|
2013-09-03 18:22:03 +08:00
|
|
|
auto touch = touches[0];
|
2012-11-19 16:28:37 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto diff = touch->getDelta();
|
|
|
|
auto node = getChildByTag(kTagTileMap);
|
|
|
|
auto currentPos = node->getPosition();
|
2013-07-11 16:38:58 +08:00
|
|
|
node->setPosition(currentPos + diff);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileMapTestScene::runThisTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = nextTileMapAction();
|
2013-07-23 08:25:44 +08:00
|
|
|
addChild(layer);
|
2010-11-18 14:50:28 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// fix bug #486, #419.
|
2013-06-20 14:17:10 +08:00
|
|
|
// "test" is the default value in Director::setGLDefaultValues()
|
2012-04-19 14:35:52 +08:00
|
|
|
// but TransitionTest may setDepthTest(false), we should revert it here
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->setDepthTest(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2010-11-18 14:50:28 +08:00
|
|
|
}
|
2011-07-06 14:56:05 +08:00
|
|
|
|
2011-07-12 14:21:29 +08:00
|
|
|
TMXGIDObjectsTest::TMXGIDObjectsTest()
|
2011-07-06 14:56:05 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = TMXTiledMap::create("TileMaps/test-object-layer.tmx");
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(map, -1, kTagTileMap);
|
2011-07-06 14:56:05 +08:00
|
|
|
|
2013-06-20 14:17:10 +08:00
|
|
|
Size CC_UNUSED s = map->getContentSize();
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLOG("Contentsize: %f, %f", s.width, s.height);
|
2011-07-06 14:56:05 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLOG("----> Iterating over all the group objets");
|
2013-08-16 16:05:27 +08:00
|
|
|
//auto group = map->objectGroupNamed("Object Layer 1");
|
2011-07-06 14:56:05 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-07-12 14:21:29 +08:00
|
|
|
void TMXGIDObjectsTest::draw()
|
2011-07-06 14:56:05 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto map = (TMXTiledMap*)getChildByTag(kTagTileMap);
|
|
|
|
auto group = map->getObjectGroup("Object Layer 1");
|
2011-07-06 14:56:05 +08:00
|
|
|
|
2013-12-03 14:47:35 +08:00
|
|
|
auto& objects = group->getObjects();
|
|
|
|
for (auto& obj : objects)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-04 17:46:57 +08:00
|
|
|
ValueMap& dict = obj.asValueMap();
|
2013-12-03 14:47:35 +08:00
|
|
|
|
|
|
|
float x = dict["x"].asFloat();
|
|
|
|
float y = dict["y"].asFloat();
|
|
|
|
float width = dict["width"].asFloat();
|
|
|
|
float height = dict["height"].asFloat();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
glLineWidth(3);
|
|
|
|
|
2013-07-26 05:49:43 +08:00
|
|
|
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));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
glLineWidth(1);
|
|
|
|
}
|
2011-07-06 14:56:05 +08:00
|
|
|
}
|
|
|
|
|
2011-07-12 14:21:29 +08:00
|
|
|
string TMXGIDObjectsTest::title()
|
2011-07-06 14:56:05 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "TMX GID objects";
|
2011-07-06 14:56:05 +08:00
|
|
|
}
|
|
|
|
|
2011-07-12 14:21:29 +08:00
|
|
|
string TMXGIDObjectsTest::subtitle()
|
2011-07-06 14:56:05 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Tiles are created from an object group";
|
2011-07-06 14:56:05 +08:00
|
|
|
}
|