2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
#include "TileMapTest2.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "2d/FastTMXLayer.h"
|
|
|
|
#include "2d/FastTMXTiledMap.h"
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2014-07-17 10:46:20 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
enum
|
2014-06-06 17:33:27 +08:00
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
kTagTileMap = 1,
|
|
|
|
};
|
2014-06-27 18:00:06 +08:00
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
FastTileMapTests::FastTileMapTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(TMXIsoZorderNew);
|
|
|
|
ADD_TEST_CASE(TMXOrthoZorderNew);
|
|
|
|
ADD_TEST_CASE(TMXIsoVertexZNew);
|
|
|
|
ADD_TEST_CASE(TMXOrthoVertexZNew);
|
|
|
|
ADD_TEST_CASE(TMXOrthoTestNew);
|
|
|
|
ADD_TEST_CASE(TMXOrthoTest2New);
|
|
|
|
ADD_TEST_CASE(TMXOrthoTest3New);
|
|
|
|
ADD_TEST_CASE(TMXOrthoTest4New);
|
|
|
|
ADD_TEST_CASE(TMXIsoTestNew);
|
|
|
|
ADD_TEST_CASE(TMXIsoTest1New);
|
|
|
|
ADD_TEST_CASE(TMXIsoTest2New);
|
|
|
|
ADD_TEST_CASE(TMXUncompressedTestNew);
|
|
|
|
ADD_TEST_CASE(TMXHexTestNew);
|
|
|
|
ADD_TEST_CASE(TMXReadWriteTestNew);
|
|
|
|
ADD_TEST_CASE(TMXTilesetTestNew);
|
|
|
|
ADD_TEST_CASE(TMXOrthoObjectsTestNew);
|
|
|
|
ADD_TEST_CASE(TMXIsoObjectsTestNew);
|
|
|
|
ADD_TEST_CASE(TMXResizeTestNew);
|
|
|
|
ADD_TEST_CASE(TMXIsoMoveLayerNew);
|
|
|
|
ADD_TEST_CASE(TMXOrthoMoveLayerNew);
|
|
|
|
ADD_TEST_CASE(TMXOrthoFlipTestNew);
|
|
|
|
ADD_TEST_CASE(TMXOrthoFlipRunTimeTestNew);
|
|
|
|
ADD_TEST_CASE(TMXOrthoFromXMLTestNew);
|
|
|
|
ADD_TEST_CASE(TMXOrthoXMLFormatTestNew);
|
|
|
|
ADD_TEST_CASE(TileMapTestNew);
|
|
|
|
ADD_TEST_CASE(TileMapEditTestNew);
|
|
|
|
ADD_TEST_CASE(TMXBug987New);
|
|
|
|
ADD_TEST_CASE(TMXBug787New);
|
|
|
|
ADD_TEST_CASE(TMXGIDObjectsTestNew);
|
2020-08-28 16:33:52 +08:00
|
|
|
ADD_TEST_CASE(TileAnimTestNew);
|
2023-03-07 23:26:37 +08:00
|
|
|
ADD_TEST_CASE(TileAnimTestNew2);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
TileDemoNew::TileDemoNew()
|
2014-06-06 17:33:27 +08:00
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
// fix bug #486, #419.
|
|
|
|
// "test" is the default value in Director::setGLDefaultValues()
|
|
|
|
// but TransitionTest may setDepthTest(false), we should revert it here
|
2019-06-30 11:36:52 +08:00
|
|
|
Director::getInstance()->getRenderer()->setDepthTest(true);
|
|
|
|
Director::getInstance()->getRenderer()->setDepthWrite(true);
|
2015-04-03 14:31:03 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
2022-07-15 19:17:01 +08:00
|
|
|
listener->onTouchesMoved = AX_CALLBACK_2(TileDemoNew::onTouchesMoved, this);
|
2014-06-06 17:33:27 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
TileDemoNew::~TileDemoNew() {}
|
2014-06-06 17:33:27 +08:00
|
|
|
|
|
|
|
std::string TileDemoNew::title() const
|
|
|
|
{
|
|
|
|
return "No title";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TileDemoNew::subtitle() const
|
|
|
|
{
|
|
|
|
return "drag the screen";
|
|
|
|
}
|
|
|
|
|
|
|
|
void TileDemoNew::onExit()
|
|
|
|
{
|
2015-04-03 14:31:03 +08:00
|
|
|
TestCase::onExit();
|
2019-06-30 11:36:52 +08:00
|
|
|
Director::getInstance()->getRenderer()->setDepthTest(false);
|
|
|
|
Director::getInstance()->getRenderer()->setDepthWrite(false);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
void TileDemoNew::onTouchesMoved(const std::vector<Touch*>& touches, Event* event)
|
2014-06-06 17:33:27 +08:00
|
|
|
{
|
|
|
|
auto touch = touches[0];
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto diff = touch->getDelta();
|
|
|
|
auto node = getChildByTag(kTagTileMap);
|
2014-06-06 17:33:27 +08:00
|
|
|
auto currentPos = node->getPosition();
|
|
|
|
node->setPosition(currentPos + diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TileMapTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TileMapTestNew::TileMapTestNew()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto map = TileMapAtlas::create(s_TilesPng, s_LevelMapTga, 16, 16);
|
2014-06-06 17:33:27 +08:00
|
|
|
// Convert it to "alias" (GL_LINEAR filtering)
|
|
|
|
map->getTexture()->setAntiAliasTexParameters();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
|
|
|
// If you are not going to use the Map, you can free it now
|
|
|
|
// NEW since v0.7
|
|
|
|
map->releaseMap();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
map->setAnchorPoint(Vec2(0.0f, 0.5f));
|
|
|
|
|
|
|
|
auto scale = ScaleBy::create(4, 0.8f);
|
2014-06-06 17:33:27 +08:00
|
|
|
auto scaleBack = scale->reverse();
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
auto seq = Sequence::create(scale, scaleBack, nullptr);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
|
|
|
map->runAction(RepeatForever::create(seq));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TileMapTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TileMapAtlas";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TileMapEditTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TileMapEditTestNew::TileMapEditTestNew()
|
|
|
|
{
|
|
|
|
auto map = TileMapAtlas::create(s_TilesPng, s_LevelMapTga, 16, 16);
|
|
|
|
// Create an Aliased Atlas
|
|
|
|
map->getTexture()->setAliasTexParameters();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +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:
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(TileMapEditTestNew::updateMap), 0.2f);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
map->setAnchorPoint(Vec2(0, 0));
|
|
|
|
map->setPosition(Vec2(-20, -200));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileMapEditTestNew::updateMap(float dt)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto tilemap = (TileMapAtlas*)getChildByTag(kTagTileMap);
|
|
|
|
|
2014-06-06 17:33:27 +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++) {
|
|
|
|
// Color3B c =[tilemap tileAt:Size(x,y));
|
|
|
|
// if( c.r != 0 ) {
|
2022-07-16 10:43:05 +08:00
|
|
|
// ////----AXLOG("%d,%d = %d", x,y,c.r);
|
2014-06-06 17:33:27 +08:00
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
// NEW since v0.7
|
2021-12-28 16:06:23 +08:00
|
|
|
Color3B c = tilemap->getTileAt(Vec2(13, 21));
|
2014-06-06 17:33:27 +08:00
|
|
|
c.r++;
|
|
|
|
c.r %= 50;
|
2021-12-28 16:06:23 +08:00
|
|
|
if (c.r == 0)
|
|
|
|
c.r = 1;
|
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
// NEW since v0.7
|
2021-12-28 16:06:23 +08:00
|
|
|
tilemap->setTile(c, Vec2(13, 21));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TileMapEditTestNew::title() const
|
|
|
|
{
|
|
|
|
return "Editable TileMapAtlas";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXOrthoTestNew::TMXOrthoTestNew()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Test orthogonal with 3d camera and anti-alias textures
|
|
|
|
//
|
|
|
|
// it should not flicker. No artifacts should appear
|
|
|
|
//
|
2021-12-28 16:06:23 +08:00
|
|
|
// auto color = LayerColor::create( Color4B(64,64,64,255) );
|
|
|
|
// addChild(color, -1);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/orthogonal-test2.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
|
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto scale = ScaleBy::create(10, 0.1f);
|
|
|
|
auto back = scale->reverse();
|
|
|
|
auto seq = Sequence::create(scale, back, nullptr);
|
2014-06-06 17:33:27 +08:00
|
|
|
auto repeat = RepeatForever::create(seq);
|
|
|
|
map->runAction(repeat);
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
// float x, y, z;
|
|
|
|
// map->getCamera()->getEye(&x, &y, &z);
|
|
|
|
// map->getCamera()->setEye(x-200, y, z+300);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoTestNew::onEnter()
|
|
|
|
{
|
|
|
|
TileDemoNew::onEnter();
|
|
|
|
|
|
|
|
Director::getInstance()->setProjection(Director::Projection::_3D);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoTestNew::onExit()
|
|
|
|
{
|
|
|
|
Director::getInstance()->setProjection(Director::Projection::DEFAULT);
|
|
|
|
TileDemoNew::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Orthogonal test";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoTest2New
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXOrthoTest2New::TMXOrthoTest2New()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/orthogonal-test1.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
map->runAction(ScaleBy::create(2, 0.5f));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoTest2New::title() const
|
|
|
|
{
|
|
|
|
return "TMX Ortho test2";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoTest3New
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXOrthoTest3New::TMXOrthoTest3New()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/orthogonal-test3.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
map->setScale(0.2f);
|
2021-12-28 16:06:23 +08:00
|
|
|
map->setAnchorPoint(Vec2(0.5f, 0.5f));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoTest3New::title() const
|
|
|
|
{
|
|
|
|
return "TMX anchorPoint test";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoTest4New
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXOrthoTest4New::TMXOrthoTest4New()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/orthogonal-test4.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s1 = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s1.width, s1.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
map->setAnchorPoint(Vec2(0.0f, 0.0f));
|
2014-06-06 17:33:27 +08:00
|
|
|
|
|
|
|
auto layer = map->getLayer("Layer 0");
|
2021-12-28 16:06:23 +08:00
|
|
|
auto s = layer->getLayerSize();
|
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
Sprite* sprite;
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite = layer->getTileAt(Vec2(0.0f, 0.0f));
|
2014-06-06 17:33:27 +08:00
|
|
|
sprite->setScale(2);
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite = layer->getTileAt(Vec2(s.width - 1, 0.0f));
|
2014-06-06 17:33:27 +08:00
|
|
|
sprite->setScale(2);
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite = layer->getTileAt(Vec2(0.0f, s.height - 1));
|
2014-06-06 17:33:27 +08:00
|
|
|
sprite->setScale(2);
|
2021-12-28 16:06:23 +08:00
|
|
|
sprite = layer->getTileAt(Vec2(s.width - 1, s.height - 1));
|
2014-06-06 17:33:27 +08:00
|
|
|
sprite->setScale(2);
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(TMXOrthoTest4New::removeSprite), 2);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoTest4New::removeSprite(float dt)
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
unschedule(AX_SCHEDULE_SELECTOR(TMXOrthoTest4New::removeSprite));
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = static_cast<ax::FastTMXTiledMap*>(getChildByTag(kTagTileMap));
|
2014-06-06 17:33:27 +08:00
|
|
|
auto layer = map->getLayer("Layer 0");
|
2021-12-28 16:06:23 +08:00
|
|
|
auto s = layer->getLayerSize();
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto sprite = layer->getTileAt(Vec2(s.width - 1, 0.0f));
|
|
|
|
auto sprite2 = layer->getTileAt(Vec2(s.width - 1, s.height - 1));
|
2014-06-06 17:33:27 +08:00
|
|
|
layer->removeChild(sprite, true);
|
2021-12-28 16:06:23 +08:00
|
|
|
auto sprite3 = layer->getTileAt(Vec2(2.0f, s.height - 1));
|
2014-06-06 17:33:27 +08:00
|
|
|
layer->removeChild(sprite3, true);
|
|
|
|
layer->removeChild(sprite2, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoTest4New::title() const
|
|
|
|
{
|
|
|
|
return "TMX width/height test";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXReadWriteTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SID_UPDATECOL = 100,
|
|
|
|
SID_REPAINTWITHGID,
|
|
|
|
SID_REMOVETILES
|
|
|
|
};
|
|
|
|
|
|
|
|
TMXReadWriteTestNew::TMXReadWriteTestNew()
|
|
|
|
{
|
|
|
|
_gid = 0;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/orthogonal-test2.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
|
|
|
auto layer = map->getLayer("Layer 0");
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
map->setScale(1);
|
|
|
|
|
|
|
|
auto tile0 = layer->getTileAt(Vec2(1, 63));
|
|
|
|
auto tile1 = layer->getTileAt(Vec2(2, 63));
|
|
|
|
auto tile2 = layer->getTileAt(Vec2(3, 62)); // Vec2(1,62));
|
|
|
|
auto tile3 = layer->getTileAt(Vec2(2, 62));
|
|
|
|
tile0->setAnchorPoint(Vec2(0.5f, 0.5f));
|
|
|
|
tile1->setAnchorPoint(Vec2(0.5f, 0.5f));
|
|
|
|
tile2->setAnchorPoint(Vec2(0.5f, 0.5f));
|
|
|
|
tile3->setAnchorPoint(Vec2(0.5f, 0.5f));
|
|
|
|
|
|
|
|
auto move = MoveBy::create(0.5f, Vec2(0.0f, 160.0f));
|
|
|
|
auto rotate = RotateBy::create(2, 360);
|
|
|
|
auto scale = ScaleBy::create(2, 5);
|
|
|
|
auto opacity = FadeOut::create(2);
|
|
|
|
auto fadein = FadeIn::create(2);
|
2014-06-06 17:33:27 +08:00
|
|
|
auto scaleback = ScaleTo::create(1, 1);
|
2022-07-15 19:17:01 +08:00
|
|
|
auto finish = CallFuncN::create(AX_CALLBACK_1(TMXReadWriteTestNew::removeSprite, this));
|
2021-12-28 16:06:23 +08:00
|
|
|
auto seq0 = Sequence::create(move, rotate, scale, opacity, fadein, scaleback, finish, nullptr);
|
|
|
|
auto seq1 = seq0->clone();
|
|
|
|
auto seq2 = seq0->clone();
|
|
|
|
auto seq3 = seq0->clone();
|
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
tile0->runAction(seq0);
|
|
|
|
tile1->runAction(seq1);
|
|
|
|
tile2->runAction(seq2);
|
|
|
|
tile3->runAction(seq3);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
_gid = layer->getTileGIDAt(Vec2(0, 63));
|
2022-07-16 10:43:05 +08:00
|
|
|
////----AXLOG("Tile GID at:(0,63) is: %d", _gid);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(TMXReadWriteTestNew::updateCol), 2.0f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(TMXReadWriteTestNew::repaintWithGID), 2.05f);
|
|
|
|
schedule(AX_SCHEDULE_SELECTOR(TMXReadWriteTestNew::removeTiles), 1.0f);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
////----AXLOG("++++atlas quantity: %d", layer->textureAtlas()->getTotalQuads());
|
|
|
|
////----AXLOG("++++children: %d", layer->getChildren()->count() );
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
_gid2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TMXReadWriteTestNew::removeSprite(Node* sender)
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
////----AXLOG("removing tile: %x", sender);
|
2014-06-06 17:33:27 +08:00
|
|
|
auto p = ((Node*)sender)->getParent();
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
p->removeChild((Node*)sender, true);
|
2021-12-28 16:06:23 +08:00
|
|
|
}
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
//////----AXLOG("atlas quantity: %d", p->textureAtlas()->totalQuads());
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXReadWriteTestNew::updateCol(float dt)
|
2021-12-28 16:06:23 +08:00
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = (ax::FastTMXTiledMap*)getChildByTag(kTagTileMap);
|
|
|
|
auto layer = (ax::FastTMXLayer*)map->getChildByTag(0);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
////----AXLOG("++++atlas quantity: %d", layer->textureAtlas()->getTotalQuads());
|
|
|
|
////----AXLOG("++++children: %d", layer->getChildren()->count() );
|
2014-06-06 17:33:27 +08:00
|
|
|
|
|
|
|
auto s = layer->getLayerSize();
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int y = 0; y < s.height; y++)
|
2014-06-06 17:33:27 +08:00
|
|
|
{
|
|
|
|
layer->setTileGID(_gid2, Vec2((float)3, (float)y));
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
_gid2 = (_gid2 + 1) % 80;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TMXReadWriteTestNew::repaintWithGID(float dt)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
// unschedule:_cmd);
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = (ax::FastTMXTiledMap*)getChildByTag(kTagTileMap);
|
|
|
|
auto layer = (ax::FastTMXLayer*)map->getChildByTag(0);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
auto s = layer->getLayerSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int x = 0; x < s.width; x++)
|
2014-06-06 17:33:27 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
int y = (int)s.height - 1;
|
|
|
|
unsigned int tmpgid = layer->getTileGIDAt(Vec2((float)x, (float)y));
|
|
|
|
layer->setTileGID(tmpgid + 1, Vec2((float)x, (float)y));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TMXReadWriteTestNew::removeTiles(float dt)
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
unschedule(AX_SCHEDULE_SELECTOR(TMXReadWriteTestNew::removeTiles));
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = (ax::FastTMXTiledMap*)getChildByTag(kTagTileMap);
|
|
|
|
auto layer = (ax::FastTMXLayer*)map->getChildByTag(0);
|
2021-12-28 16:06:23 +08:00
|
|
|
auto s = layer->getLayerSize();
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int y = 0; y < s.height; y++)
|
2014-06-06 17:33:27 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
layer->removeTileAt(Vec2(5.0, (float)y));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXReadWriteTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Read/Write test";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXHexTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXHexTestNew::TMXHexTestNew()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto color = LayerColor::create(Color4B(64, 64, 64, 255));
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(color, -1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/hexa-test.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXHexTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Hex tes";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXIsoTestNew::TMXIsoTestNew()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto color = LayerColor::create(Color4B(64, 64, 64, 255));
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(color, -1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/iso-test.tmx");
|
2021-12-28 16:06:23 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
// move map to the center of the screen
|
|
|
|
auto ms = map->getMapSize();
|
|
|
|
auto ts = map->getTileSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
map->runAction(MoveTo::create(1.0f, Vec2(-ms.width * ts.width / 2, -ms.height * ts.height / 2)));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Isometric test 0";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoTest1New
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXIsoTest1New::TMXIsoTest1New()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto color = LayerColor::create(Color4B(64, 64, 64, 255));
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(color, -1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/iso-test1.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
map->setAnchorPoint(Vec2(0.5f, 0.5f));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoTest1New::title() const
|
|
|
|
{
|
|
|
|
return "TMX Isometric test + anchorPoint";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoTest2New
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXIsoTest2New::TMXIsoTest2New()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto color = LayerColor::create(Color4B(64, 64, 64, 255));
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(color, -1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/iso-test2.tmx");
|
2021-12-28 16:06:23 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
// move map to the center of the screen
|
|
|
|
auto ms = map->getMapSize();
|
|
|
|
auto ts = map->getTileSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
map->runAction(MoveTo::create(1.0f, Vec2(-ms.width * ts.width / 2, -ms.height * ts.height / 2)));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoTest2New::title() const
|
|
|
|
{
|
|
|
|
return "TMX Isometric test 2";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXUncompressedTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXUncompressedTestNew::TMXUncompressedTestNew()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto color = LayerColor::create(Color4B(64, 64, 64, 255));
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(color, -1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/iso-test2-uncompressed.tmx");
|
2021-12-28 16:06:23 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
// move map to the center of the screen
|
|
|
|
auto ms = map->getMapSize();
|
|
|
|
auto ts = map->getTileSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
map->runAction(MoveTo::create(1.0f, Vec2(-ms.width * ts.width / 2, -ms.height * ts.height / 2)));
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
// unsupported
|
|
|
|
// // testing release map
|
|
|
|
// TMXLayer* layer;
|
|
|
|
//
|
|
|
|
// auto& children = map->getChildren();
|
|
|
|
// for(const auto &node : children) {
|
|
|
|
// layer= static_cast<TMXLayer*>(node);
|
|
|
|
// layer->releaseMap();
|
|
|
|
// }
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXUncompressedTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Uncompressed test";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXTilesetTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXTilesetTestNew::TMXTilesetTestNew()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/orthogonal-test5.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXTilesetTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Tileset test";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoObjectsTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXOrthoObjectsTestNew::TMXOrthoObjectsTestNew()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/ortho-objects.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, -1, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
auto group = map->getObjectGroup("Object Group 1");
|
2014-06-06 17:33:27 +08:00
|
|
|
auto& objects = group->getObjects();
|
|
|
|
|
|
|
|
Value objectsVal = Value(objects);
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("%s", objectsVal.getDescription().c_str());
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-11 15:39:56 +08:00
|
|
|
auto drawNode = DrawNode::create();
|
|
|
|
Color4F color(1.0, 1.0, 1.0, 1.0);
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&& obj : objects)
|
2014-06-06 17:33:27 +08:00
|
|
|
{
|
|
|
|
ValueMap& dict = obj.asValueMap();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
float x = dict["x"].asFloat();
|
|
|
|
float y = dict["y"].asFloat();
|
|
|
|
float width = dict["width"].asFloat();
|
2020-08-18 11:33:18 +08:00
|
|
|
float height = dict["height"].asFloat();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-11 15:39:56 +08:00
|
|
|
drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
|
|
|
|
drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);
|
2021-12-28 16:06:23 +08:00
|
|
|
drawNode->drawLine(Vec2(x + width, y + height), Vec2(x, y + height), color);
|
|
|
|
drawNode->drawLine(Vec2(x, y + height), Vec2(x, y), color);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
2014-09-11 15:39:56 +08:00
|
|
|
map->addChild(drawNode);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoObjectsTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Ortho object test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoObjectsTestNew::subtitle() const
|
|
|
|
{
|
|
|
|
return "You should see a white box around the 3 platforms";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoObjectsTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
TMXIsoObjectsTestNew::TMXIsoObjectsTestNew()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/iso-test-objectgroup.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, -1, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
|
|
|
auto group = map->getObjectGroup("Object Group 1");
|
|
|
|
|
|
|
|
auto& objects = group->getObjects();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
Value objectsVal = Value(objects);
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("%s", objectsVal.getDescription().c_str());
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-11 15:39:56 +08:00
|
|
|
auto drawNode = DrawNode::create();
|
|
|
|
Color4F color(1.0, 1.0, 1.0, 1.0);
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&& obj : objects)
|
2014-06-06 17:33:27 +08:00
|
|
|
{
|
|
|
|
ValueMap& dict = obj.asValueMap();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
float x = dict["x"].asFloat();
|
|
|
|
float y = dict["y"].asFloat();
|
|
|
|
float width = dict["width"].asFloat();
|
2020-08-18 11:33:18 +08:00
|
|
|
float height = dict["height"].asFloat();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-11 15:39:56 +08:00
|
|
|
drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
|
|
|
|
drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);
|
2021-12-28 16:06:23 +08:00
|
|
|
drawNode->drawLine(Vec2(x + width, y + height), Vec2(x, y + height), color);
|
|
|
|
drawNode->drawLine(Vec2(x, y + height), Vec2(x, y), color);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
2014-09-11 15:39:56 +08:00
|
|
|
map->addChild(drawNode, 10);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoObjectsTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Iso object test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoObjectsTestNew::subtitle() const
|
|
|
|
{
|
|
|
|
return "You need to parse them manually. See bug #810";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXResizeTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
TMXResizeTestNew::TMXResizeTestNew()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/orthogonal-test5.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
ax::FastTMXLayer* layer;
|
2014-06-06 17:33:27 +08:00
|
|
|
layer = map->getLayer("Layer 0");
|
|
|
|
|
|
|
|
auto ls = layer->getLayerSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
for (unsigned int y = 0; y < ls.height; y++)
|
2014-06-06 17:33:27 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
for (unsigned int x = 0; x < ls.width; x++)
|
2014-06-06 17:33:27 +08:00
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
layer->setTileGID(1, Vec2((float)x, (float)y));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
}
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXResizeTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX resize test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXResizeTestNew::subtitle() const
|
|
|
|
{
|
|
|
|
return "Should not crash. Testing issue #740";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoZorderNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXIsoZorderNew::TMXIsoZorderNew()
|
|
|
|
{
|
2019-06-30 11:36:52 +08:00
|
|
|
Director::getInstance()->getRenderer()->setDepthTest(false);
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/iso-test-zorder.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
auto s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
map->setPosition(Vec2(-s.width / 2, 0.0f));
|
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
_tamara = Sprite::create(s_pathSister1);
|
2021-12-28 16:06:23 +08:00
|
|
|
map->addChild(_tamara, (int)map->getChildren().size());
|
2014-06-06 17:33:27 +08:00
|
|
|
_tamara->retain();
|
|
|
|
int mapWidth = map->getMapSize().width * map->getTileSize().width;
|
2022-07-15 19:17:01 +08:00
|
|
|
_tamara->setPosition(AX_POINT_PIXELS_TO_POINTS(Vec2(mapWidth / 2.0f, 0.0f)));
|
2021-12-28 16:06:23 +08:00
|
|
|
_tamara->setAnchorPoint(Vec2(0.5f, 0.0f));
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto move = MoveBy::create(10, Vec2(300.0f, 250.0f));
|
2014-06-06 17:33:27 +08:00
|
|
|
auto back = move->reverse();
|
2021-12-28 16:06:23 +08:00
|
|
|
auto seq = Sequence::create(move, back, nullptr);
|
|
|
|
_tamara->runAction(RepeatForever::create(seq));
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(TMXIsoZorderNew::repositionSprite));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TMXIsoZorderNew::~TMXIsoZorderNew()
|
|
|
|
{
|
|
|
|
_tamara->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TMXIsoZorderNew::onExit()
|
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
unschedule(AX_SCHEDULE_SELECTOR(TMXIsoZorderNew::repositionSprite));
|
2014-06-06 17:33:27 +08:00
|
|
|
TileDemoNew::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TMXIsoZorderNew::repositionSprite(float dt)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto p = _tamara->getPosition();
|
2022-07-15 19:17:01 +08:00
|
|
|
p = AX_POINT_POINTS_TO_PIXELS(p);
|
2014-06-06 17:33:27 +08:00
|
|
|
auto map = getChildByTag(kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +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
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
int newZ = 4 - (p.y / 48);
|
2021-12-28 16:06:23 +08:00
|
|
|
newZ = std::max(newZ, 0);
|
|
|
|
|
|
|
|
map->reorderChild(_tamara, newZ);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoZorderNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Iso Zorder";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoZorderNew::subtitle() const
|
|
|
|
{
|
|
|
|
return "Sprite should hide behind the trees";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoZorderNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXOrthoZorderNew::TMXOrthoZorderNew()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/orthogonal-test-zorder.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
_tamara = Sprite::create(s_pathSister1);
|
2021-12-28 16:06:23 +08:00
|
|
|
map->addChild(_tamara, (int)map->getChildren().size());
|
2014-06-06 17:33:27 +08:00
|
|
|
_tamara->retain();
|
2021-12-28 16:06:23 +08:00
|
|
|
_tamara->setAnchorPoint(Vec2(0.5f, 0.0f));
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto move = MoveBy::create(10, Vec2(400.0f, 450.0f));
|
2014-06-06 17:33:27 +08:00
|
|
|
auto back = move->reverse();
|
2021-12-28 16:06:23 +08:00
|
|
|
auto seq = Sequence::create(move, back, nullptr);
|
|
|
|
_tamara->runAction(RepeatForever::create(seq));
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(TMXOrthoZorderNew::repositionSprite));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TMXOrthoZorderNew::~TMXOrthoZorderNew()
|
|
|
|
{
|
|
|
|
_tamara->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoZorderNew::repositionSprite(float dt)
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
auto p = _tamara->getPosition();
|
2022-07-15 19:17:01 +08:00
|
|
|
p = AX_POINT_POINTS_TO_PIXELS(p);
|
2014-06-06 17:33:27 +08:00
|
|
|
auto map = getChildByTag(kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +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
|
|
|
|
|
|
|
|
// -10: customization for this particular sample
|
2021-12-28 16:06:23 +08:00
|
|
|
int newZ = 4 - ((p.y - 10) / 81);
|
|
|
|
newZ = std::max(newZ, 0);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
|
|
|
map->reorderChild(_tamara, newZ);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoZorderNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Ortho Zorder";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoZorderNew::subtitle() const
|
|
|
|
{
|
|
|
|
return "Sprite should hide behind the trees";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoVertexZNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXIsoVertexZNew::TMXIsoVertexZNew()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/iso-test-vertexz.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
auto s = map->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
map->setPosition(Vec2(-s.width / 2, 0.0f));
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
// because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you
|
|
|
|
// can use any Sprite and it will work OK.
|
|
|
|
auto layer = map->getLayer("Trees");
|
2021-12-28 16:06:23 +08:00
|
|
|
_tamara = layer->getTileAt(Vec2(29.0f, 29.0f));
|
2014-06-06 17:33:27 +08:00
|
|
|
_tamara->retain();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
auto move = MoveBy::create(10, Vec2(300, 250) * (1 / AX_CONTENT_SCALE_FACTOR()));
|
2014-06-06 17:33:27 +08:00
|
|
|
auto back = move->reverse();
|
2021-12-28 16:06:23 +08:00
|
|
|
auto seq = Sequence::create(move, back, nullptr);
|
|
|
|
_tamara->runAction(RepeatForever::create(seq));
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(TMXIsoVertexZNew::repositionSprite));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TMXIsoVertexZNew::~TMXIsoVertexZNew()
|
|
|
|
{
|
|
|
|
_tamara->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TMXIsoVertexZNew::repositionSprite(float dt)
|
|
|
|
{
|
|
|
|
// tile height is 64x32
|
|
|
|
// map size: 30x30
|
2021-12-28 16:06:23 +08:00
|
|
|
auto p = _tamara->getPosition();
|
2022-07-15 19:17:01 +08:00
|
|
|
p = AX_POINT_POINTS_TO_PIXELS(p);
|
2021-12-28 16:06:23 +08:00
|
|
|
float newZ = -(p.y + 32) / 16;
|
|
|
|
_tamara->setPositionZ(newZ);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXIsoVertexZNew::onEnter()
|
|
|
|
{
|
|
|
|
TileDemoNew::onEnter();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
// TIP: 2d projection should be used
|
|
|
|
Director::getInstance()->setProjection(Director::Projection::_2D);
|
2019-06-30 11:36:52 +08:00
|
|
|
Director::getInstance()->getRenderer()->setDepthTest(true);
|
|
|
|
Director::getInstance()->getRenderer()->setDepthWrite(true);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXIsoVertexZNew::onExit()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
// At exit use any other projection.
|
2014-06-06 17:33:27 +08:00
|
|
|
Director::getInstance()->setProjection(Director::Projection::DEFAULT);
|
2019-06-30 11:36:52 +08:00
|
|
|
Director::getInstance()->getRenderer()->setDepthTest(false);
|
|
|
|
Director::getInstance()->getRenderer()->setDepthWrite(false);
|
2014-06-06 17:33:27 +08:00
|
|
|
TileDemoNew::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoVertexZNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Iso VertexZ";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoVertexZNew::subtitle() const
|
|
|
|
{
|
2014-06-06 18:03:44 +08:00
|
|
|
return "Doesn't support yet";
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoVertexZNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXOrthoVertexZNew::TMXOrthoVertexZNew()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/orthogonal-test-vertexz.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
// because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you
|
|
|
|
// can use any Sprite and it will work OK.
|
|
|
|
auto layer = map->getLayer("trees");
|
2021-12-28 16:06:23 +08:00
|
|
|
_tamara = layer->getTileAt(Vec2(0, 11));
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("%p vertexZ: %f", _tamara, _tamara->getPositionZ());
|
2014-06-06 17:33:27 +08:00
|
|
|
_tamara->retain();
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
auto move = MoveBy::create(10, Vec2(400, 450) * (1 / AX_CONTENT_SCALE_FACTOR()));
|
2014-06-06 17:33:27 +08:00
|
|
|
auto back = move->reverse();
|
2021-12-28 16:06:23 +08:00
|
|
|
auto seq = Sequence::create(move, back, nullptr);
|
|
|
|
_tamara->runAction(RepeatForever::create(seq));
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(TMXOrthoVertexZNew::repositionSprite));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TMXOrthoVertexZNew::~TMXOrthoVertexZNew()
|
|
|
|
{
|
|
|
|
_tamara->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoVertexZNew::repositionSprite(float dt)
|
|
|
|
{
|
|
|
|
// tile height is 101x81
|
|
|
|
// map size: 12x12
|
|
|
|
auto p = _tamara->getPosition();
|
2022-07-15 19:17:01 +08:00
|
|
|
p = AX_POINT_POINTS_TO_PIXELS(p);
|
2021-12-28 16:06:23 +08:00
|
|
|
_tamara->setPositionZ(-((p.y + 81) / 81));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoVertexZNew::onEnter()
|
|
|
|
{
|
|
|
|
TileDemoNew::onEnter();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
// TIP: 2d projection should be used
|
|
|
|
Director::getInstance()->setProjection(Director::Projection::_2D);
|
2019-06-30 11:36:52 +08:00
|
|
|
Director::getInstance()->getRenderer()->setDepthTest(true);
|
|
|
|
Director::getInstance()->getRenderer()->setDepthWrite(true);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoVertexZNew::onExit()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
// At exit use any other projection.
|
2014-06-06 17:33:27 +08:00
|
|
|
Director::getInstance()->setProjection(Director::Projection::DEFAULT);
|
2019-06-30 11:36:52 +08:00
|
|
|
Director::getInstance()->getRenderer()->setDepthTest(false);
|
|
|
|
Director::getInstance()->getRenderer()->setDepthWrite(false);
|
2014-06-06 17:33:27 +08:00
|
|
|
TileDemoNew::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoVertexZNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Ortho vertexZ";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoVertexZNew::subtitle() const
|
|
|
|
{
|
2014-06-06 18:03:44 +08:00
|
|
|
return "Doesn't support yet";
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXIsoMoveLayerNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXIsoMoveLayerNew::TMXIsoMoveLayerNew()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/iso-test-movelayer.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
map->setPosition(Vec2(-700.0f, -50.0f));
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoMoveLayerNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Iso Move Layer";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXIsoMoveLayerNew::subtitle() const
|
|
|
|
{
|
|
|
|
return "Trees should be horizontally aligned";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoMoveLayerNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXOrthoMoveLayerNew::TMXOrthoMoveLayerNew()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/orthogonal-test-movelayer.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoMoveLayerNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Ortho Move Layer";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoMoveLayerNew::subtitle() const
|
|
|
|
{
|
|
|
|
return "Trees should be horizontally aligned";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXTilePropertyTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
TMXTilePropertyTestNew::TMXTilePropertyTestNew()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/ortho-tile-property.tmx");
|
2021-12-28 16:06:23 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
for (int i = 1; i <= 20; i++)
|
|
|
|
{
|
|
|
|
for (const auto& value : map->getPropertiesForGID(i).asValueMap())
|
2014-06-06 17:33:27 +08:00
|
|
|
{
|
|
|
|
log("GID:%i, Properties:%s, %s", i, value.first.c_str(), value.second.asString().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXTilePropertyTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX Tile Property Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXTilePropertyTestNew::subtitle() const
|
|
|
|
{
|
|
|
|
return "In the console you should see tile properties";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoFlipTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
TMXOrthoFlipTestNew::TMXOrthoFlipTestNew()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/ortho-rotation-test.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
log("ContentSize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
|
|
|
auto action = ScaleBy::create(2, 0.5f);
|
|
|
|
map->runAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoFlipTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX tile flip test";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoFlipRunTimeTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
TMXOrthoFlipRunTimeTestNew::TMXOrthoFlipRunTimeTestNew()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/ortho-rotation-test.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
auto s = map->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
log("ContentSize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
|
|
|
auto action = ScaleBy::create(2, 0.5f);
|
|
|
|
map->runAction(action);
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
schedule(AX_SCHEDULE_SELECTOR(TMXOrthoFlipRunTimeTestNew::flipIt), 1.0f);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoFlipRunTimeTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX tile flip run time test";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoFlipRunTimeTestNew::subtitle() const
|
|
|
|
{
|
|
|
|
return "in 2 sec bottom left tiles will flip";
|
|
|
|
}
|
|
|
|
|
|
|
|
void TMXOrthoFlipRunTimeTestNew::flipIt(float dt)
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = (ax::FastTMXTiledMap*)getChildByTag(kTagTileMap);
|
2014-06-06 17:33:27 +08:00
|
|
|
auto layer = map->getLayer("Layer 0");
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
// blue diamond
|
|
|
|
auto tileCoord = Vec2(1, 10);
|
2014-06-06 17:33:27 +08:00
|
|
|
int flags;
|
|
|
|
unsigned int GID = layer->getTileGIDAt(tileCoord, (TMXTileFlags*)&flags);
|
|
|
|
// Vertical
|
2021-12-28 16:06:23 +08:00
|
|
|
if (flags & kTMXTileVerticalFlag)
|
2014-06-06 17:33:27 +08:00
|
|
|
flags &= ~kTMXTileVerticalFlag;
|
|
|
|
else
|
|
|
|
flags |= kTMXTileVerticalFlag;
|
2021-12-28 16:06:23 +08:00
|
|
|
layer->setTileGID(GID, tileCoord, (TMXTileFlags)flags);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
tileCoord = Vec2(1, 8);
|
|
|
|
GID = layer->getTileGIDAt(tileCoord, (TMXTileFlags*)&flags);
|
2014-06-06 17:33:27 +08:00
|
|
|
// Vertical
|
2021-12-28 16:06:23 +08:00
|
|
|
if (flags & kTMXTileVerticalFlag)
|
2014-06-06 17:33:27 +08:00
|
|
|
flags &= ~kTMXTileVerticalFlag;
|
|
|
|
else
|
2021-12-28 16:06:23 +08:00
|
|
|
flags |= kTMXTileVerticalFlag;
|
|
|
|
layer->setTileGID(GID, tileCoord, (TMXTileFlags)flags);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
tileCoord = Vec2(2, 8);
|
|
|
|
GID = layer->getTileGIDAt(tileCoord, (TMXTileFlags*)&flags);
|
2014-06-06 17:33:27 +08:00
|
|
|
// Horizontal
|
2021-12-28 16:06:23 +08:00
|
|
|
if (flags & kTMXTileHorizontalFlag)
|
2014-06-06 17:33:27 +08:00
|
|
|
flags &= ~kTMXTileHorizontalFlag;
|
|
|
|
else
|
2021-12-28 16:06:23 +08:00
|
|
|
flags |= kTMXTileHorizontalFlag;
|
|
|
|
layer->setTileGID(GID, tileCoord, (TMXTileFlags)flags);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoFromXMLTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
TMXOrthoFromXMLTestNew::TMXOrthoFromXMLTestNew()
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
std::string resources = "TileMaps"; // partial paths are OK as resource paths.
|
|
|
|
std::string file = resources + "/orthogonal-test1.tmx";
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto fileUtils = FileUtils::getInstance();
|
metal support for cocos2d-x (#19305)
* remove deprecated files
* remove some deprecated codes
* remove more deprecated codes
* remove ui deprecated codes
* remove more deprecated codes
* remove deprecated codes in ccmenuitem
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes in ui
* remove more deprecated codes
* remove more deprecated codes
* remove more deprecated codes
* remove vr related codes and ignore some modules
* remove allocator
* remove some config
* 【Feature】add back-end project file
* [Feature] add back-end file
* add pipeline descriptor and shader cache
* [Feature] support sprite for backend
* [Feature] remove unneeded code
* [Feature] according to es2.0 spec, you must use clamp-to-edge as texture wrap mode, and no mipmapping for non-power-of-two texture
* [Feature] set texture wrap mode to clamp-to-edge, and no mipmapping for non-power-of-two texture
* [Feature] remove macro define to .cpp file
* [Feature] add log info
* [Feature] add PipelineDescriptor for TriangleCommand
* [Feature] add PipelineDescriptor object as member of TriangleCommand
* [Feature] add getPipelineDescriptor method
* add renderbackend
* complete pipeline descriptor
* [Feature] add viewport in RenderCommand
* set viewport when rendrering
* [Feature] occur error when using RendererBackend, to be fixed.
* a workaround to fix black screen on macOS 10.14 (#19090)
* add rendererbackend init function
* fix typo
* [Feature] modify testFile
* [BugFix] modify shader path
* [Feature] set default viewport
* fix projection
* [Feature] modify log info
* [BugFix] change viewport data type to int
* [BugFix] add BindGroup to PipelienDescriptor
* [BugFix] change a_position to vec3 in sprite.vert
* [BugFix] set vertexLayout according to V3F_C4B_T2F structure
* [Feature] revert a_position to vec4
* [Feature] renderer should not use gl codes directly
* [Feature] it's better not use default value parameter
* fix depth test setting
* rendererbackend -> renderer
* clear color and depth at begin
* add metal backend
* metal support normalized attribute
* simplify codes
* update external
* add render pass desctriptor in pipeline descriptor
* fix warnings
* fix crash and memeory leak
* refactor Texture2D
* put pipeline descriptor into render command
* simplify codes
* [Feature] update Sprite
* fix crash when closing app
* [Feature] update SpriteBatchNode and TextureAtlas
* support render texture(not finish)
* [Feature] remove unused code
* make tests work on mac
* fix download-deps path error
* make tests work on iOS
* [Feature] support ttf under normal label effect
* refactor triangle command processing
* let renderer handle more common commands
* refactor backend
* make render texture work
* [Feature] refactor backend for GL
* [Feature]Renaming to make it easy to understand
* [Feature] change warp mode to CLAMP_TO_EDGE
* fix ghost
* simplify visit render queue logic
* support progress timer without rial mode
* support partcile system
* Feature/update label (#149)
* [BugFix] fix compile error
* [Feature] support outline effect in ios
* [Feature] add shader file
* [BugFix] fix begin and end RenderPass
* [Feature] update CustomCommand
* [Feature] revert project.pbxproj
* [Feature] simplify codes
* [BugFix] pack AI88 to RGBA8888 only when outline enable
* [Feature] support shadow effect in Label
* [Feature] support BMFont
* [Feature] support glow effect
* [Feature] simplify shader files
* LabelAtlas work
* handle blend function correctly
* support tile map
* don't share buffer in metal
* alloc buffer size as needed
* support more tilemap
* Merge branch 'minggo/metal-support' into feature/updateLabel
* minggo/metal-support:
support tile map
handle blend function correctly
LabelAtlas work
Feature/update label (#149)
support partcile system
# Conflicts:
# cocos/2d/CCLabel.cpp
# cocos/2d/CCSprite.cpp
# cocos/2d/CCSpriteBatchNode.cpp
# cocos/renderer/CCQuadCommand.cpp
# cocos/renderer/CCQuadCommand.h
* render texture work without saving file
* use global viewport
* grid3d works
* remove grabber
* tiled3d works
* [BugFix] fix label bug
* [Feature] add updateSubData for buffer
* [Feature] remove setVertexCount
* support depth test
* add callback command
* [Feature] add UITest
* [Feature] update UITest
* [Feature] remove unneeded codes
* fix custom command issue
* fix layer color blend issue
* [BugFix] fix iOS compile error
* [Feature] remove unneeded codes
* [Feature] fix updateVertexBuffer
* layerradial works
* add draw test back
* fix batch issue
* fix compiling error
* [BugFix] support ETC1
* [BugFix] get the correct pipelineDescriptor
* [BugFix] skip draw when backendTexture nullptr
* clipping node support
* [Feature] add shader files
* fix stencil issue in metal
* [Feature] update UILayoutTest
* [BugFix] skip drawing when vertexCount is zero
* refactor renderer
* add set global z order for stencil manager commands
* fix warnings caused by type
* remove viewport in render command
* [Feature] fix warnings caused by type
* [BugFix] clear vertexCount and indexCount for CustomComand when needed
* [Feature] update clear for CustomCommand
* ios use metal
* fix viewport issue
* fix LayerColorGradient crash
* [cmake] transport to android and windows (#160)
* save point 1
* compile on windows
* run on android
* revert useless change
* android set CC_ENABLE_CACHE_TEXTURE_DATA to 1
* add initGlew
* fix android crash
* add TODO new-renderer
* review update
* revert onGLFWWindowPosCallback
* fix android compiling error
* Impl progress radial (#162)
* progresstimer add radial impl
* default drawType to element
* dec invoke times of createVertexBuffer (#163)
* support depth/stencil format for gl backend
* simplify progress timer codes
* support motionstreak, effect is wrong
* fix motionstreak issue
* [Feature] update Scissor Test (#161)
* [Feature] update Scissor Test
* [Feature] update ScissorTest
* [Feature] rename function
* [Feature] get constant reference if needed
* [Feature] show render status (#164)
* improve performance
* fix depth state
* fill error that triangle vertex/index number bigger than buffer
* fix compiline error in release mode
* fix buffer conflict between CPU and GPU on iOS/macOS
* Renderer refactor (#165)
* use one vertes/index buffer with opengl
* fix error on windows
* custom command support index format config
* CCLayer: compact vertex data structure
* update comment
* fix doc
* support fast tilemap
* pass index format instead
* fix some wrong effect
* fix render texture error
* fix texture per-element size
* fix texture format error
* BlendFunc type refactor, GLenum -> backend::BlendFactor (#167)
* BlendFunc use backend::BlendFactor as inner field
* update comments
* use int to replace GLenum
* update xcode project fiel
* rename to GLBlendConst
* add ccConstants.h
* update xcode project file
* update copyright
* remove primitive command
* remove CCPrimitive.cpp/.h
* remove deprecated files
* remove unneeded files
* remove multiple view support
* remove multiple view support
* remove the usage of frame buffer in camera
* director don't use frame buffer
* remove FrameBuffer
* remove BatchCommand
* add some api reference
* add physics2d back
* fix crash when close app on mac
* improve render texture
* fix rendertexture issue
* fix rendertexture issue
* simplify codes
* CMake support for mac & ios (#169)
* update cmake
* fix compile error
* update 3rd libs version
* remove CCThread.h/.cpp
* remove ccthread
* use audio engine to implement simple audio engine
* remove unneeded codes
* remove deprecated codes
* remove winrt macro
* remove CC_USE_WIC
* set partcile blend function in more elegant way
* remove unneeded codes
* remove unneeded codes
* cmake works on windows
* update project setting
* improve performance
* GLFloat -> float
* sync v3 cmake improvements into metal-support (#172)
* pick: modern cmake, compile definitions improvement (#19139)
* modern cmake, use target_compile_definitions partly
* simplify macro define, remove USE_*
* modern cmake, macro define
* add physics 2d macro define into ccConfig.h
* remove USE_CHIPMUNK macro in build.gradle
* remove CocosSelectModule.cmake
* shrink useless define
* simplify compile options config, re-add if necessary
* update external for tmp CI test
* un-quote target_compile_options value
* add "-g" parameter only when debug mode
* keep single build type when generator Xcode & VS projecy
* update external for tmp CI tes
* add static_cast<char>(-1), fix -Wc++11-narrowing
* simplify win32 compile define
* not modify code, only improve compile options
# Conflicts:
# .gitignore
# cmake/Modules/CocosConfigDepend.cmake
# cocos/CMakeLists.txt
# external/config.json
# tests/cpp-tests/CMakeLists.txt
* modern cmake, improve cmake_compiler_flags (#19145)
* cmake_compiler_flags
* Fix typo
* Fix typo2
* Remove chanages from Android.mk
* correct lua template cmake build (#19149)
* don't add -Wno-deprecated into jsb target
* correct lua template cmake build
* fix win32 lua template compile error
* prevent cmake in-source-build friendly (#19151)
* pick: Copy resources to "Resources/" on win32 like in linux configuration
* add "/Z7" for cpp-tests on windows
* [cmake] fix iOS xcode property setting failed (#19208)
* fix iOS xcode property setting failed
* use search_depend_libs_recursive at dlls collect
* fix typo
* [cmake] add find_host_library into iOS toolchain file (#19230)
* pick: [lua android] use luajit & template cmake update (#19239)
* increase cmake stability , remove tests/CMakeLists.txt (#19261)
* cmake win32 Precompiled header (#19273)
* Precompiled header
* Fix
* Precompiled header for cocos
* Precompiled header jscocos2d
* Fix for COCOS2D_DEBUG is always 1 on Android (#19291)
Related #19289
* little build fix, tests cpp-tests works on mac
* sync v3 build related codes into metal-support (#173)
* strict initialization for std::array
* remove proj.win32 project configs
* modern cmake, cmake_cleanup_remove_unused_variables (#19146)
* Switch travis CI to xenial (#19207)
* Switch travis CI to xenial
* Remove language: android
* Set language: cpp
* Fix java problem
* Update sdkmanager
* Fix sdkmanger
* next sdkmanager fix
* Remove xenial from android
* revert to sdk-tools-{system}-3859397
* Remove linux cmake install
* Update before-install.sh
* Update .travis.yml
* Simplify install-deps-linux.sh, tested on Ubuntu 16.04 (#19212)
* Simplify install-deps-linux.sh
* Cleanup
* pick: install ninja
* update cocos2d-console submodule
* for metal-support alpha release, we only test cpp
* add HelloCpp into project(Cocos2d-x) for tmp test
* update extenal metal-support-4
* update uniform setting
* [Feature] update BindGroup
* [Feature] empty-test
* [Feature] cpp-test
* [Feature] fix GL compiler error
* [Feature] fix GL crash
* [Feature] empty-test
* [Feature] cpp-tests
* [feature] improve frameRate
* [feature] fix opengl compile error
* [feature] fix opengl compile error
* [BugFix] fix compute maxLocation error
* [Feature] update setting unifrom
* [Feature] fix namespace
* [Feature] remove unneeded code
* [Bugfix] fix project file
* [Feature] update review
* [texture2d] impl texture format support (#175)
* texture update
* update
* update texture
* commit
* compile on windows
* ddd
* rename
* rename methods
* no crash
* save gl
* save
* save
* rename
* move out pixel format convert functions
* metal crash
* update
* update android
* support gles compressed texture format
* support more compress format
* add more conversion methods
* ss
* save
* update conversion methods
* add PVRTC format support
* reformat
* add marco linux
* fix GL marcro
* pvrtc supported only by ios 8.0+
* remove unused cmake
* revert change
* refactor Texture2D::initWithData
* fix conversion log
* refactor Texture2D::initWithData
* remove some OpenGL constants for PVRTC
* add todo
* fix typo
* AutoTest works on mac/iOS by disable part cases, sync v3 bug fix (#174)
* review cpp-tests, and fix part issues on start auto test
* sync png format fix: Node:Particle3D abnormal texture effects #19204
* fix cpp-tests SpritePolygon crash, wrong png format (#19170)
* fix wrong png convert format from sRGB to Gray
* erase plist index if all frames was erased
* test_A8.png have I8 format, fix it
* [CCSpriteCache] allow re-add plist & add testcase (#19175)
* allow re-add plist & add testcase
* remove comments/rename method/update testcase
* fix isSpriteFramesWithFileLoaded & add testcase
* remove used variable
* remove unused variable
* fix double free issues when js/lua-tests exit on iOS (#19236)
* disable part cases, AutoTest works without crash on mac
* update cocos2dx files json, to test cocos new next
* fix spritecache plist parsing issue (#19269)
* [linux] Fix FileUtils::getContents with folder (#19157)
* fix FileUtils::getContents on linux/mac
* use stat.st_mode
* simplify
* [CCFileUtils] win32 getFileSize (#19176)
* win32 getFileSize
* fix stat
* [cpp test-Android]20:FileUtils/2 change title (#19197)
* sync #19200
* sync #19231
* [android lua] improve performance of lua loader (#19234)
* [lua] improve performance of lua loader
* remove cache fix
* Revert "fix spritecache plist parsing issue (#19269)"
This reverts commit f3a85ece4307a7b90816c34489d1ed2c8fd11baf.
* remove win32 project files ref in template.json
* add metal framework lnk ref into cpp template
* test on iOS, and disable part cases
* alBufferData instead of alBufferDataStatic for small audio file on Apple (#19227)
* changes AudioCache to use alBufferData instead of alBufferDataStatic
(also makes test 19 faster to trigger openal bugs faster)
The original problem: CrashIfClientProvidedBogusAudioBufferList
https://github.com/cocos2d/cocos2d-x/issues/18948
is not happening anymore, but there's still a not very frequent issue
that makes OpenAL crash with a call stack like this.
AudioCache::readDataTask > alBufferData > CleanUpDeadBufferList
It happes more frequently when the device is "cold", which means after
half an hour of not using the device (locked).
I could not find the actual source code for iOS OpenAL, so I used the
macOS versions:
https://opensource.apple.com/source/OpenAL/OpenAL-48.7/Source/OpenAL/oalImp.cpp.auto.html
They seem to use CAGuard.h to make sure the dead buffer list
has no threading issues. I'm worried because the CAGuard code I found
has macos and win32 define but no iOS, so I'm not sure. I guess the
iOS version is different and has the guard.
I could not find a place in the code that's unprotected by the locks
except the InitializeBufferMap() which should not be called more than
once from cocos, and there's a workaround in AudioEngine-impl for it.
I reduced the occurence of the CleanUpDeadBufferList crash by moving
the guard in ~AudioCache to cover the alDeleteBuffers call.
* remove hack method "setTimeout" on audio
* AutoTest works on iOS
* support set ios deployment target for root project
* enable all texture2d cases, since Jiang have fixed
* add CCTextureUtils to xcode project file (#176)
* add leak cases for SpriteFrameCache (#177)
* re-add SpriteFrameCache cases
* update template file json
* Update SpriteFrameCacheTest.cpp
* fix compiling error
2019-01-18 15:08:25 +08:00
|
|
|
std::string str = fileUtils->getStringFromFile(fileUtils->fullPathForFilename(file.c_str()));
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::createWithXML(str, resources.c_str());
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
auto s = map->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
log("ContentSize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
|
|
|
auto action = ScaleBy::create(2, 0.5f);
|
|
|
|
map->runAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoFromXMLTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX created from XML test";
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXOrthoXMLFormatTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
TMXOrthoXMLFormatTestNew::TMXOrthoXMLFormatTestNew()
|
|
|
|
{
|
|
|
|
// this test tests for:
|
|
|
|
// 1. load xml format tilemap
|
|
|
|
// 2. gid lower than firstgid is ignored
|
|
|
|
// 3. firstgid in tsx is ignored, tile property in tsx loaded correctly.
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/xml-test.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
auto s = map->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
log("ContentSize: %f, %f", s.width, s.height);
|
|
|
|
|
|
|
|
for (int i = 24; i <= 26; i++)
|
|
|
|
{
|
2014-06-06 17:33:27 +08:00
|
|
|
log("GID:%i, Properties:%s", i, map->getPropertiesForGID(i).asValueMap()["name"].asString().c_str());
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-06-06 17:33:27 +08:00
|
|
|
auto action = ScaleBy::create(2, 0.5f);
|
|
|
|
map->runAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXOrthoXMLFormatTestNew::title() const
|
|
|
|
{
|
|
|
|
return "you should see blue, green and yellow in console.";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXBug987New
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXBug987New::TMXBug987New()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/orthogonal-test6.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s1 = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s1.width, s1.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2019-09-24 11:31:35 +08:00
|
|
|
map->setAnchorPoint(Vec2(0.0f, 0.0f));
|
2014-06-06 17:33:27 +08:00
|
|
|
auto layer = map->getLayer("Tile Layer 1");
|
2021-12-28 16:06:23 +08:00
|
|
|
layer->setTileGID(3, Vec2(2, 2));
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXBug987New::title() const
|
|
|
|
{
|
|
|
|
return "TMX Bug 987";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXBug987New::subtitle() const
|
|
|
|
{
|
2023-03-12 16:15:11 +08:00
|
|
|
return "You should see a square";
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXBug787New
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXBug787New::TMXBug787New()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/iso-test-bug787.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
map->setScale(0.25f);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXBug787New::title() const
|
|
|
|
{
|
|
|
|
return "TMX Bug 787";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXBug787New::subtitle() const
|
|
|
|
{
|
|
|
|
return "You should see a map";
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TMXGIDObjectsTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TMXGIDObjectsTestNew::TMXGIDObjectsTestNew()
|
|
|
|
{
|
2022-10-18 19:17:36 +08:00
|
|
|
auto map = ax::FastTMXTiledMap::create("TileMaps/test-object-layer.tmx");
|
2014-06-06 17:33:27 +08:00
|
|
|
addChild(map, -1, kTagTileMap);
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("Contentsize: %f, %f", s.width, s.height);
|
2014-06-06 17:33:27 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("----> Iterating over all the group objects");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-11 15:39:56 +08:00
|
|
|
auto drawNode = DrawNode::create();
|
|
|
|
Color4F color(1.0, 1.0, 1.0, 1.0);
|
2021-12-28 16:06:23 +08:00
|
|
|
auto group = map->getObjectGroup("Object Layer 1");
|
2014-09-11 15:39:56 +08:00
|
|
|
auto objects = group->getObjects();
|
2022-07-21 19:19:08 +08:00
|
|
|
for (auto&& obj : objects)
|
2014-06-06 17:33:27 +08:00
|
|
|
{
|
|
|
|
ValueMap& dict = obj.asValueMap();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
float x = dict["x"].asFloat();
|
|
|
|
float y = dict["y"].asFloat();
|
|
|
|
float width = dict["width"].asFloat();
|
2020-08-18 11:33:18 +08:00
|
|
|
float height = dict["height"].asFloat();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
2014-09-11 15:39:56 +08:00
|
|
|
drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
|
|
|
|
drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);
|
2021-12-28 16:06:23 +08:00
|
|
|
drawNode->drawLine(Vec2(x + width, y + height), Vec2(x, y + height), color);
|
|
|
|
drawNode->drawLine(Vec2(x, y + height), Vec2(x, y), color);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
2014-09-11 15:39:56 +08:00
|
|
|
map->addChild(drawNode, 10);
|
2014-06-06 17:33:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXGIDObjectsTestNew::title() const
|
|
|
|
{
|
|
|
|
return "TMX GID objects";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TMXGIDObjectsTestNew::subtitle() const
|
|
|
|
{
|
|
|
|
return "Tiles are created from an object group";
|
|
|
|
}
|
2020-08-28 16:33:52 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TileAnimTestNew
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TileAnimTestNew::TileAnimTestNew()
|
|
|
|
{
|
|
|
|
|
|
|
|
map = FastTMXTiledMap::create("TileMaps/tile_animation_test.tmx");
|
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
2022-07-15 19:17:01 +08:00
|
|
|
listener->onTouchesBegan = AX_CALLBACK_2(TileAnimTestNew::onTouchBegan, this);
|
2020-08-28 16:33:52 +08:00
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
2020-08-28 16:33:52 +08:00
|
|
|
|
|
|
|
map->setTileAnimEnabled(_animStarted);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TileAnimTestNew::title() const
|
|
|
|
{
|
2023-03-12 16:15:11 +08:00
|
|
|
return "Tile animation test.\nClick to toggle the animation";
|
2020-08-28 16:33:52 +08:00
|
|
|
}
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
void TileAnimTestNew::onTouchBegan(const std::vector<ax::Touch*>& touches, ax::Event* event)
|
2020-08-28 16:33:52 +08:00
|
|
|
{
|
|
|
|
_animStarted = !_animStarted;
|
|
|
|
map->setTileAnimEnabled(_animStarted);
|
|
|
|
}
|
2023-03-07 23:26:37 +08:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// TileAnimTestNew2
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
TileAnimTestNew2::TileAnimTestNew2()
|
|
|
|
{
|
|
|
|
|
|
|
|
map = FastTMXTiledMap::create("TileMaps/tile_animation_test_2.tmx");
|
|
|
|
addChild(map, 0, kTagTileMap);
|
|
|
|
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
|
|
|
listener->onTouchesBegan = AX_CALLBACK_2(TileAnimTestNew2::onTouchBegan, this);
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
|
|
|
|
|
|
|
Size AX_UNUSED s = map->getContentSize();
|
|
|
|
AXLOG("ContentSize: %f, %f", s.width, s.height);
|
|
|
|
|
|
|
|
map->setTileAnimEnabled(_animStarted);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TileAnimTestNew2::title() const
|
|
|
|
{
|
2023-03-12 16:15:11 +08:00
|
|
|
return "Tile animation test with flipped/rotated.\nClick to toggle the animation";
|
2023-03-07 23:26:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TileAnimTestNew2::onTouchBegan(const std::vector<ax::Touch*>& touches, ax::Event* event)
|
|
|
|
{
|
|
|
|
_animStarted = !_animStarted;
|
|
|
|
map->setTileAnimEnabled(_animStarted);
|
|
|
|
}
|