PuzzleSDK
TileMapTest.cpp
浏览该文件的文档.
1/****************************************************************************
2 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
3
4 http://www.cocos2d-x.org
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 ****************************************************************************/
24
25#include "TileMapTest.h"
26#include "../testResource.h"
27
28
30
31enum
32{
34};
35
36//------------------------------------------------------------------
37//
38// TileDemo
39//
40//------------------------------------------------------------------
41
42
43TileMapTests::TileMapTests()
44{
83}
84
86{
87 // fix bug #486, #419.
88 // "test" is the default value in Director::setGLDefaultValues()
89 // but TransitionTest may setDepthTest(false), we should revert it here
90 Director::getInstance()->getRenderer()->setDepthTest(true);
91 Director::getInstance()->getRenderer()->setDepthWrite(true);
92 Director::getInstance()->getRenderer()->setDepthCompareFunction(backend::CompareFunction::LESS_EQUAL);
93
94 auto listener = EventListenerTouchAllAtOnce::create();
95 listener->onTouchesMoved = CC_CALLBACK_2(TileDemo::onTouchesMoved, this);
96 _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
97}
98
100{
101}
102
103std::string TileDemo::title() const
104{
105 return "No title";
106}
107
108std::string TileDemo::subtitle() const
109{
110 return "drag the screen";
111}
112
114{
115 TestCase::onExit();
116 Director::getInstance()->getRenderer()->setDepthTest(false);
117 Director::getInstance()->getRenderer()->setDepthWrite(false);
118}
119
120void TileDemo::onTouchesMoved(const std::vector<Touch*>& touches, Event *event)
121{
122 auto touch = touches[0];
123
124 auto diff = touch->getDelta();
125 auto node = getChildByTag(kTagTileMap);
126 auto currentPos = node->getPosition();
127 node->setPosition(currentPos + diff);
128}
129
130//------------------------------------------------------------------
131//
132// TileMapTest
133//
134//------------------------------------------------------------------
136{
137 auto map = TileMapAtlas::create(s_TilesPng, s_LevelMapTga, 16, 16);
138 // Convert it to "alias" (GL_LINEAR filtering)
139 map->getTexture()->setAntiAliasTexParameters();
140
141 Size CC_UNUSED s = map->getContentSize();
142 CCLOG("ContentSize: %f, %f", s.width,s.height);
143
144 // If you are not going to use the Map, you can free it now
145 // NEW since v0.7
146 map->releaseMap();
147
148 addChild(map, 0, kTagTileMap);
149
150 map->setAnchorPoint( Vec2(0.0f, 0.5f) );
151
152 auto scale = ScaleBy::create(4, 0.8f);
153 auto scaleBack = scale->reverse();
154
155 auto seq = Sequence::create(scale, scaleBack, nullptr);
156
157 map->runAction(RepeatForever::create(seq));
158}
159
160std::string TileMapTest::title() const
161{
162 return "TileMapAtlas";
163}
164
165//------------------------------------------------------------------
166//
167// TileMapEditTest
168//
169//------------------------------------------------------------------
171{
172 auto map = TileMapAtlas::create(s_TilesPng, s_LevelMapTga, 16, 16);
173 // Create an Aliased Atlas
174 map->getTexture()->setAliasTexParameters();
175
176 Size CC_UNUSED s = map->getContentSize();
177 CCLOG("ContentSize: %f, %f", s.width,s.height);
178
179 // If you are not going to use the Map, you can free it now
180 // [tilemap releaseMap);
181 // And if you are going to use, it you can access the data with:
182 schedule(CC_SCHEDULE_SELECTOR(TileMapEditTest::updateMap), 0.2f);
183
184 addChild(map, 0, kTagTileMap);
185
186 map->setAnchorPoint( Vec2(0, 0) );
187 map->setPosition( Vec2(-20,-200) );
188}
189
191{
192 // IMPORTANT
193 // The only limitation is that you cannot change an empty, or assign an empty tile to a tile
194 // The value 0 not rendered so don't assign or change a tile with value 0
195
196 auto tilemap = (TileMapAtlas*) getChildByTag(kTagTileMap);
197
198 //
199 // For example you can iterate over all the tiles
200 // using this code, but try to avoid the iteration
201 // over all your tiles in every frame. It's very expensive
202 // for(int x=0; x < tilemap.tgaInfo->width; x++) {
203 // for(int y=0; y < tilemap.tgaInfo->height; y++) {
204 // Color3B c =[tilemap tileAt:Size(x,y));
205 // if( c.r != 0 ) {
206 // ////----CCLOG("%d,%d = %d", x,y,c.r);
207 // }
208 // }
209 // }
210
211 // NEW since v0.7
212 Color3B c = tilemap->getTileAt(Vec2(13,21));
213 c.r++;
214 c.r %= 50;
215 if( c.r==0)
216 c.r=1;
217
218 // NEW since v0.7
219 tilemap->setTile(c, Vec2(13,21) );
220}
221
222std::string TileMapEditTest::title() const
223{
224 return "Editable TileMapAtlas";
225}
226
227//------------------------------------------------------------------
228//
229// TMXOrthoTest
230//
231//------------------------------------------------------------------
233{
234 //
235 // Test orthogonal with 3d camera and anti-alias textures
236 //
237 // it should not flicker. No artifacts should appear
238 //
239 //auto color = LayerColor::create( Color4B(64,64,64,255) );
240 //addChild(color, -1);
241
242 auto map = TMXTiledMap::create("TileMaps/orthogonal-test2.tmx");
243
244 addChild(map, 0, kTagTileMap);
245
246 Size CC_UNUSED s = map->getContentSize();
247 CCLOG("ContentSize: %f, %f", s.width,s.height);
248
249 auto scale = ScaleBy::create(10, 0.1f);
250 auto back = scale->reverse();
251 auto seq = Sequence::create(scale, back, nullptr);
252 auto repeat = RepeatForever::create(seq);
253 map->runAction(repeat);
254
255// float x, y, z;
256// map->getCamera()->getEye(&x, &y, &z);
257// map->getCamera()->setEye(x-200, y, z+300);
258}
259
261{
263
264 Director::getInstance()->setProjection(Director::Projection::_3D);
265}
266
268{
269 Director::getInstance()->setProjection(Director::Projection::DEFAULT);
271}
272
273std::string TMXOrthoTest::title() const
274{
275 return "TMX Orthogonal test";
276}
277
279{
280
281 auto map = TMXTiledMap::create("TileMaps/test-staggered.tmx");
282
283 addChild(map, 0, kTagTileMap);
284
285}
286
288{
290
291 Director::getInstance()->setProjection(Director::Projection::_3D);
292}
293
295{
296 Director::getInstance()->setProjection(Director::Projection::DEFAULT);
298}
299
300std::string TMXStaggeredTest::title() const
301{
302 return "TMX Staggered test";
303}
304
305//------------------------------------------------------------------
306//
307// TMXOrthoTest2
308//
309//------------------------------------------------------------------
311{
312 auto map = TMXTiledMap::create("TileMaps/orthogonal-test1.tmx");
313 addChild(map, 0, kTagTileMap);
314
315 Size CC_UNUSED s = map->getContentSize();
316 CCLOG("ContentSize: %f, %f", s.width,s.height);
317
318 auto& children = map->getChildren();
319 SpriteBatchNode* child = nullptr;
320
321 for(const auto &obj : children) {
322 child = static_cast<SpriteBatchNode*>(obj);
323 child->getTexture()->setAntiAliasTexParameters();
324 }
325
326 map->runAction( ScaleBy::create(2, 0.5f) ) ;
327}
328
329std::string TMXOrthoTest2::title() const
330{
331 return "TMX Ortho test2";
332}
333
334//------------------------------------------------------------------
335//
336// TMXOrthoTest3
337//
338//------------------------------------------------------------------
340{
341 auto map = TMXTiledMap::create("TileMaps/orthogonal-test3.tmx");
342 addChild(map, 0, kTagTileMap);
343
344 Size CC_UNUSED s = map->getContentSize();
345 CCLOG("ContentSize: %f, %f", s.width,s.height);
346
347 auto& children = map->getChildren();
348 SpriteBatchNode* child = nullptr;
349
350 for(const auto &node : children) {
351 child = static_cast<SpriteBatchNode*>(node);
352 child->getTexture()->setAntiAliasTexParameters();
353 }
354
355 map->setScale(0.2f);
356 map->setAnchorPoint( Vec2(0.5f, 0.5f) );
357}
358
359std::string TMXOrthoTest3::title() const
360{
361 return "TMX anchorPoint test";
362}
363
364//------------------------------------------------------------------
365//
366// TMXOrthoTest4
367//
368//------------------------------------------------------------------
370{
371 auto map = TMXTiledMap::create("TileMaps/orthogonal-test4.tmx");
372 addChild(map, 0, kTagTileMap);
373
374 Size CC_UNUSED s1 = map->getContentSize();
375 CCLOG("ContentSize: %f, %f", s1.width,s1.height);
376
377 SpriteBatchNode* child = nullptr;
378
379 auto& children = map->getChildren();
380
381 for(const auto &node : children) {
382 child = static_cast<SpriteBatchNode*>(node);
383 child->getTexture()->setAntiAliasTexParameters();
384 }
385
386 map->setAnchorPoint(Vec2(0.0f, 0.0f));
387
388 auto layer = map->getLayer("Layer 0");
389 auto s = layer->getLayerSize();
390
391 layer->setOpacity(128);
392
393 Sprite* sprite;
394 sprite = layer->getTileAt(Vec2(0.0f,0.0f));
395 sprite->setScale(2);
396 sprite = layer->getTileAt(Vec2(s.width-1,0.0f));
397 sprite->setScale(2);
398 sprite = layer->getTileAt(Vec2(0.0f,s.height-1));
399 sprite->setScale(2);
400 sprite = layer->getTileAt(Vec2(s.width-1,s.height-1));
401 sprite->setScale(2);
402
403 schedule( CC_SCHEDULE_SELECTOR(TMXOrthoTest4::removeSprite), 2 );
404
405}
406
408{
409 unschedule(CC_SCHEDULE_SELECTOR(TMXOrthoTest4::removeSprite));
410
411 auto map = static_cast<TMXTiledMap*>( getChildByTag(kTagTileMap) );
412 auto layer = map->getLayer("Layer 0");
413 auto s = layer->getLayerSize();
414
415 auto sprite = layer->getTileAt( Vec2(s.width-1,0.0f) );
416 auto sprite2 = layer->getTileAt(Vec2(s.width-1, s.height-1));
417 layer->removeChild(sprite, true);
418 auto sprite3 = layer->getTileAt(Vec2(2.0f, s.height-1));
419 layer->removeChild(sprite3, true);
420 layer->removeChild(sprite2, true);
421}
422
423std::string TMXOrthoTest4::title() const
424{
425 return "TMX width/height test";
426}
427
428//------------------------------------------------------------------
429//
430// TMXReadWriteTest
431//
432//------------------------------------------------------------------
433enum
434{
439
441{
442 _gid = 0;
443
444 auto map = TMXTiledMap::create("TileMaps/orthogonal-test2.tmx");
445 addChild(map, 0, kTagTileMap);
446
447 Size CC_UNUSED s = map->getContentSize();
448 CCLOG("ContentSize: %f, %f", s.width,s.height);
449
450
451 auto layer = map->getLayer("Layer 0");
452 layer->getTexture()->setAntiAliasTexParameters();
453
454 map->setScale( 1 );
455
456 auto tile0 = layer->getTileAt(Vec2(1,63));
457 auto tile1 = layer->getTileAt(Vec2(2,63));
458 auto tile2 = layer->getTileAt(Vec2(3,62));//Vec2(1,62));
459 auto tile3 = layer->getTileAt(Vec2(2,62));
460 tile0->setAnchorPoint( Vec2(0.5f, 0.5f) );
461 tile1->setAnchorPoint( Vec2(0.5f, 0.5f) );
462 tile2->setAnchorPoint( Vec2(0.5f, 0.5f) );
463 tile3->setAnchorPoint( Vec2(0.5f, 0.5f) );
464
465 auto move = MoveBy::create(0.5f, Vec2(0.0f,160.0f));
466 auto rotate = RotateBy::create(2, 360);
467 auto scale = ScaleBy::create(2, 5);
468 auto opacity = FadeOut::create(2);
469 auto fadein = FadeIn::create(2);
470 auto scaleback = ScaleTo::create(1, 1);
471 auto finish = CallFuncN::create(CC_CALLBACK_1(TMXReadWriteTest::removeSprite, this));
472 auto seq0 = Sequence::create(move, rotate, scale, opacity, fadein, scaleback, finish, nullptr);
473 auto seq1 = seq0->clone();
474 auto seq2 = seq0->clone();
475 auto seq3 = seq0->clone();
476
477 tile0->runAction(seq0);
478 tile1->runAction(seq1);
479 tile2->runAction(seq2);
480 tile3->runAction(seq3);
481
482
483 _gid = layer->getTileGIDAt(Vec2(0,63));
485
486 schedule(CC_SCHEDULE_SELECTOR(TMXReadWriteTest::updateCol), 2.0f);
487 schedule(CC_SCHEDULE_SELECTOR(TMXReadWriteTest::repaintWithGID), 2.05f);
488 schedule(CC_SCHEDULE_SELECTOR(TMXReadWriteTest::removeTiles), 1.0f);
489
492
493 _gid2 = 0;
494}
495
497{
499 auto p = ((Node*)sender)->getParent();
500
501 if (p)
502 {
503 p->removeChild((Node*)sender, true);
504 }
505
507}
508
510{
511 auto map = (TMXTiledMap*)getChildByTag(kTagTileMap);
512 auto layer = (TMXLayer*)map->getChildByTag(0);
513
516
517
518 auto s = layer->getLayerSize();
519
520 for( int y=0; y< s.height; y++ )
521 {
522 layer->setTileGID(_gid2, Vec2((float)3, (float)y));
523 }
524
525 _gid2 = (_gid2 + 1) % 80;
526}
527
529{
530// unschedule:_cmd);
531
532 auto map = (TMXTiledMap*)getChildByTag(kTagTileMap);
533 auto layer = (TMXLayer*)map->getChildByTag(0);
534
535 auto s = layer->getLayerSize();
536 for( int x=0; x<s.width;x++)
537 {
538 int y = (int)s.height-1;
539 unsigned int tmpgid = layer->getTileGIDAt( Vec2((float)x, (float)y) );
540 layer->setTileGID(tmpgid+1, Vec2((float)x, (float)y));
541 }
542}
543
545{
546 unschedule(CC_SCHEDULE_SELECTOR(TMXReadWriteTest::removeTiles));
547
548 auto map = (TMXTiledMap*)getChildByTag(kTagTileMap);
549 auto layer = (TMXLayer*)map->getChildByTag(0);
550 auto s = layer->getLayerSize();
551
552 for( int y=0; y< s.height; y++ )
553 {
554 layer->removeTileAt( Vec2(5.0, (float)y) );
555 }
556}
557
558
559
560std::string TMXReadWriteTest::title() const
561{
562 return "TMX Read/Write test";
563}
564
565//------------------------------------------------------------------
566//
567// TMXHexTest
568//
569//------------------------------------------------------------------
571{
572 auto color = LayerColor::create( Color4B(64,64,64,255) );
573 addChild(color, -1);
574
575 auto map = TMXTiledMap::create("TileMaps/hexa-test.tmx");
576 addChild(map, 0, kTagTileMap);
577
578 Size CC_UNUSED s = map->getContentSize();
579 CCLOG("ContentSize: %f, %f", s.width,s.height);
580}
581
582std::string TMXHexTest::title() const
583{
584 return "TMX Hex tes";
585}
586
587//------------------------------------------------------------------
588//
589// TMXIsoTest
590//
591//------------------------------------------------------------------
593{
594 auto color = LayerColor::create( Color4B(64,64,64,255) );
595 addChild(color, -1);
596
597 auto map = TMXTiledMap::create("TileMaps/iso-test.tmx");
598 addChild(map, 0, kTagTileMap);
599
600 // move map to the center of the screen
601 auto ms = map->getMapSize();
602 auto ts = map->getTileSize();
603 map->runAction( MoveTo::create(1.0f, Vec2( -ms.width * ts.width/2, -ms.height * ts.height/2 )) );
604}
605
606std::string TMXIsoTest::title() const
607{
608 return "TMX Isometric test 0";
609}
610
611//------------------------------------------------------------------
612//
613// TMXIsoTest1
614//
615//------------------------------------------------------------------
617{
618 auto color = LayerColor::create( Color4B(64,64,64,255) );
619 addChild(color, -1);
620
621 auto map = TMXTiledMap::create("TileMaps/iso-test1.tmx");
622 addChild(map, 0, kTagTileMap);
623
624 Size CC_UNUSED s = map->getContentSize();
625 CCLOG("ContentSize: %f, %f", s.width,s.height);
626
627 map->setAnchorPoint(Vec2(0.5f, 0.5f));
628}
629
630std::string TMXIsoTest1::title() const
631{
632 return "TMX Isometric test + anchorPoint";
633}
634
635//------------------------------------------------------------------
636//
637// TMXIsoTest2
638//
639//------------------------------------------------------------------
641{
642 auto color = LayerColor::create( Color4B(64,64,64,255) );
643 addChild(color, -1);
644
645 auto map = TMXTiledMap::create("TileMaps/iso-test2.tmx");
646 addChild(map, 0, kTagTileMap);
647
648 Size CC_UNUSED s = map->getContentSize();
649 CCLOG("ContentSize: %f, %f", s.width,s.height);
650
651 // move map to the center of the screen
652 auto ms = map->getMapSize();
653 auto ts = map->getTileSize();
654 map->runAction( MoveTo::create(1.0f, Vec2( -ms.width * ts.width/2, -ms.height * ts.height/2 ) ));
655}
656
657std::string TMXIsoTest2::title() const
658{
659 return "TMX Isometric test 2";
660}
661
662//------------------------------------------------------------------
663//
664// TMXUncompressedTest
665//
666//------------------------------------------------------------------
668{
669 auto color = LayerColor::create( Color4B(64,64,64,255) );
670 addChild(color, -1);
671
672 auto map = TMXTiledMap::create("TileMaps/iso-test2-uncompressed.tmx");
673 addChild(map, 0, kTagTileMap);
674
675 Size CC_UNUSED s = map->getContentSize();
676 CCLOG("ContentSize: %f, %f", s.width,s.height);
677
678 // move map to the center of the screen
679 auto ms = map->getMapSize();
680 auto ts = map->getTileSize();
681 map->runAction(MoveTo::create(1.0f, Vec2( -ms.width * ts.width/2, -ms.height * ts.height/2 ) ));
682
683 // testing release map
684 TMXLayer* layer;
685
686 auto& children = map->getChildren();
687 for(const auto &node : children) {
688 layer= static_cast<TMXLayer*>(node);
689 layer->releaseMap();
690 }
691
692}
693
694std::string TMXUncompressedTest::title() const
695{
696 return "TMX Uncompressed test";
697}
698
699//------------------------------------------------------------------
700//
701// TMXTilesetTest
702//
703//------------------------------------------------------------------
705{
706 auto map = TMXTiledMap::create("TileMaps/orthogonal-test5.tmx");
707 addChild(map, 0, kTagTileMap);
708
709 Size CC_UNUSED s = map->getContentSize();
710 CCLOG("ContentSize: %f, %f", s.width,s.height);
711
712 TMXLayer* layer;
713 layer = map->getLayer("Layer 0");
714 layer->getTexture()->setAntiAliasTexParameters();
715
716 layer = map->getLayer("Layer 1");
717 layer->getTexture()->setAntiAliasTexParameters();
718
719 layer = map->getLayer("Layer 2");
720 layer->getTexture()->setAntiAliasTexParameters();
721}
722
723std::string TMXTilesetTest::title() const
724{
725 return "TMX Tileset test";
726}
727
728//------------------------------------------------------------------
729//
730// TMXCvsFormatTest
731//
732//------------------------------------------------------------------
733
735{
736 auto map = TMXTiledMap::create("TileMaps/orthogonal-test5-csv.tmx");
737 CCASSERT(map, "Map was not created. Probably failed to parse!");
738 addChild(map, 0, kTagTileMap);
739
740 Size CC_UNUSED s = map->getContentSize();
741 CCLOG("ContentSize: %f, %f", s.width,s.height);
742
743 TMXLayer* layer;
744 layer = map->getLayer("Layer 0");
745 layer->getTexture()->setAntiAliasTexParameters();
746
747 layer = map->getLayer("Layer 1");
748 layer->getTexture()->setAntiAliasTexParameters();
749
750 layer = map->getLayer("Layer 2");
751 layer->getTexture()->setAntiAliasTexParameters();
752}
753
754std::string TMXCvsFormatTest::title() const
755{
756 return "TMX CSV Parsing test";
757}
758
759//------------------------------------------------------------------
760//
761// TMXOrthoObjectsTest
762//
763//------------------------------------------------------------------
765{
766 auto map = TMXTiledMap::create("TileMaps/ortho-objects.tmx");
767 addChild(map, -1, kTagTileMap);
768
769 Size CC_UNUSED s = map->getContentSize();
770 CCLOG("ContentSize: %f, %f", s.width,s.height);
771
772 auto group = map->getObjectGroup("Object Group 1");
773 auto& objects = group->getObjects();
774
775 Value objectsVal = Value(objects);
776 CCLOG("%s", objectsVal.getDescription().c_str());
777
778 auto drawNode = DrawNode::create();
779
780 for (auto& obj : objects)
781 {
782 ValueMap& dict = obj.asValueMap();
783
784 float x = dict["x"].asFloat();
785 float y = dict["y"].asFloat();
786 float width = dict["width"].asFloat();
787 float height = dict["height"].asFloat();
788
789 Color4F color(1.0, 1.0, 1.0, 1.0);
790
791 drawNode->drawLine( Vec2(x, y), Vec2((x+width), y), color );
792 drawNode->drawLine( Vec2((x+width), y), Vec2((x+width), (y+height)), color );
793 drawNode->drawLine( Vec2((x+width), (y+height)), Vec2(x, (y+height)), color );
794 drawNode->drawLine( Vec2(x, (y+height)), Vec2(x, y), color );
795 }
796 map->addChild(drawNode);
797}
798
799std::string TMXOrthoObjectsTest::title() const
800{
801 return "TMX Ortho object test";
802}
803
805{
806 return "You should see a white box around the 3 platforms";
807}
808
809
810//------------------------------------------------------------------
811//
812// TMXIsoObjectsTest
813//
814//------------------------------------------------------------------
815
817{
818 auto map = TMXTiledMap::create("TileMaps/iso-test-objectgroup.tmx");
819 addChild(map, -1, kTagTileMap);
820
821 Size CC_UNUSED s = map->getContentSize();
822 CCLOG("ContentSize: %f, %f", s.width,s.height);
823
824 auto group = map->getObjectGroup("Object Group 1");
825
826 auto& objects = group->getObjects();
827
828 Value objectsVal = Value(objects);
829 CCLOG("%s", objectsVal.getDescription().c_str());
830
831 auto drawNode = DrawNode::create();
832
833 for (auto& obj : objects)
834 {
835 ValueMap& dict = obj.asValueMap();
836
837 float x = dict["x"].asFloat();
838 float y = dict["y"].asFloat();
839 float width = dict["width"].asFloat();
840 float height = dict["height"].asFloat();
841
842 Color4F color(1.0, 1.0, 1.0, 1.0);
843
844 drawNode->drawLine( Vec2(x, y), Vec2((x+width), y), color );
845 drawNode->drawLine( Vec2((x+width), y), Vec2((x+width), (y+height)), color );
846 drawNode->drawLine( Vec2((x+width), (y+height)), Vec2(x, (y+height)), color );
847 drawNode->drawLine( Vec2(x, (y+height)), Vec2(x, y), color );
848 }
849 map->addChild(drawNode, 10);
850}
851
852std::string TMXIsoObjectsTest::title() const
853{
854 return "TMX Iso object test";
855}
856
858{
859 return "You need to parse them manually. See bug #810";
860}
861
862
863//------------------------------------------------------------------
864//
865// TMXResizeTest
866//
867//------------------------------------------------------------------
868
870{
871 auto map = TMXTiledMap::create("TileMaps/orthogonal-test5.tmx");
872 addChild(map, 0, kTagTileMap);
873
874 Size CC_UNUSED s = map->getContentSize();
875 CCLOG("ContentSize: %f, %f", s.width,s.height);
876
877 TMXLayer* layer;
878 layer = map->getLayer("Layer 0");
879
880 auto ls = layer->getLayerSize();
881 for (unsigned int y = 0; y < ls.height; y++)
882 {
883 for (unsigned int x = 0; x < ls.width; x++)
884 {
885 layer->setTileGID(1, Vec2( (float)x, (float)y ) );
886 }
887 }
888}
889
890std::string TMXResizeTest::title() const
891{
892 return "TMX resize test";
893}
894
895std::string TMXResizeTest::subtitle() const
896{
897 return "Should not crash. Testing issue #740";
898}
899
900
901//------------------------------------------------------------------
902//
903// TMXIsoZorder
904//
905//------------------------------------------------------------------
907{
908 Director::getInstance()->getRenderer()->setDepthTest(false);
909 auto map = TMXTiledMap::create("TileMaps/iso-test-zorder.tmx");
910 addChild(map, 0, kTagTileMap);
911
912 auto s = map->getContentSize();
913 CCLOG("ContentSize: %f, %f", s.width,s.height);
914 map->setPosition(Vec2(-s.width/2,0.0f));
915
916 _tamara = Sprite::create(s_pathSister1);
917 map->addChild(_tamara, (int)map->getChildren().size() );
918
919 _tamara->retain();
920 int mapWidth = map->getMapSize().width * map->getTileSize().width;
921 _tamara->setPosition(CC_POINT_PIXELS_TO_POINTS(Vec2( mapWidth/2.0f,0.0f)));
922 _tamara->setScale(0.5);
923 _tamara->setAnchorPoint(Vec2(0.5f,0.0f));
924
925
926 auto move = MoveBy::create(10, Vec2(300.0f,250.0f));
927 auto back = move->reverse();
928 auto seq = Sequence::create(move, back,nullptr);
929 _tamara->runAction( RepeatForever::create(seq) );
930
931 schedule( CC_SCHEDULE_SELECTOR(TMXIsoZorder::repositionSprite) );
932}
933
935{
936 _tamara->release();
937}
938
940{
941 unschedule(CC_SCHEDULE_SELECTOR(TMXIsoZorder::repositionSprite));
943}
944
946{
947 auto p = _tamara->getPosition();
948 p = CC_POINT_POINTS_TO_PIXELS(p);
949 auto map = getChildByTag(kTagTileMap);
950
951 // there are only 4 layers. (grass and 3 trees layers)
952 // if tamara < 30, z=4
953 // if tamara < 60, z=3
954 // if tamara < 90,z=2
955
956 int newZ = 4 - (static_cast<int>(p.y) / 30);
957 newZ = std::max(newZ,0);
958
959 map->reorderChild(_tamara, newZ);
960}
961
962std::string TMXIsoZorder::title() const
963{
964 return "TMX Iso Zorder";
965}
966
967std::string TMXIsoZorder::subtitle() const
968{
969 return "Sprite should hide behind the trees";
970}
971
972
973//------------------------------------------------------------------
974//
975// TMXOrthoZorder
976//
977//------------------------------------------------------------------
979{
980 auto map = TMXTiledMap::create("TileMaps/orthogonal-test-zorder.tmx");
981 addChild(map, 0, kTagTileMap);
982
983 Size CC_UNUSED s = map->getContentSize();
984 CCLOG("ContentSize: %f, %f", s.width,s.height);
985
986 _tamara = Sprite::create(s_pathSister1);
987 map->addChild(_tamara, (int)map->getChildren().size());
988 _tamara->retain();
989 _tamara->setAnchorPoint(Vec2(0.5f,0.0f));
990
991
992 auto move = MoveBy::create(10, Vec2(400.0f,450.0f));
993 auto back = move->reverse();
994 auto seq = Sequence::create(move, back,nullptr);
995 _tamara->runAction( RepeatForever::create(seq));
996
997 schedule( CC_SCHEDULE_SELECTOR(TMXOrthoZorder::repositionSprite));
998}
999
1001{
1002 _tamara->release();
1003}
1004
1006{
1007 auto p = _tamara->getPosition();
1008 p = CC_POINT_POINTS_TO_PIXELS(p);
1009 auto map = getChildByTag(kTagTileMap);
1010
1011 // there are only 4 layers. (grass and 3 trees layers)
1012 // if tamara < 81, z=4
1013 // if tamara < 162, z=3
1014 // if tamara < 243,z=2
1015
1016 // -10: customization for this particular sample
1017 int newZ = 4 - ( (p.y-10) / 81);
1018 newZ = std::max(newZ,0);
1019
1020 map->reorderChild(_tamara, newZ);
1021}
1022
1023std::string TMXOrthoZorder::title() const
1024{
1025 return "TMX Ortho Zorder";
1026}
1027
1028std::string TMXOrthoZorder::subtitle() const
1029{
1030 return "Sprite should hide behind the trees";
1031}
1032
1033
1034//------------------------------------------------------------------
1035//
1036// TMXIsoVertexZ
1037//
1038//------------------------------------------------------------------
1040{
1041 auto map = TMXTiledMap::create("TileMaps/iso-test-vertexz.tmx");
1042 addChild(map, 0, kTagTileMap);
1043
1044 auto s = map->getContentSize();
1045 map->setPosition( Vec2(-s.width/2,0.0f) );
1046 CCLOG("ContentSize: %f, %f", s.width,s.height);
1047
1048 // because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you
1049 // can use any Sprite and it will work OK.
1050 auto layer = map->getLayer("Trees");
1051 _tamara = layer->getTileAt( Vec2(29,29) );
1052 _tamara->retain();
1053
1054 auto move = MoveBy::create(10, Vec2(300,250) * (1/CC_CONTENT_SCALE_FACTOR()));
1055 auto back = move->reverse();
1056 auto seq = Sequence::create(move, back,nullptr);
1057 _tamara->runAction( RepeatForever::create(seq) );
1058
1059 schedule( CC_SCHEDULE_SELECTOR(TMXIsoVertexZ::repositionSprite));
1060
1061}
1062
1064{
1065 _tamara->release();
1066}
1067
1069{
1070 // tile height is 64x32
1071 // map size: 30x30
1072 auto p = _tamara->getPosition();
1073 p = CC_POINT_POINTS_TO_PIXELS(p);
1074 float newZ = -(p.y+32) /16;
1075 _tamara->setPositionZ( newZ );
1076}
1077
1079{
1081
1082 // TIP: 2d projection should be used
1083 Director::getInstance()->setProjection(Director::Projection::_2D);
1084 Director::getInstance()->getRenderer()->setDepthTest(true);
1085 Director::getInstance()->getRenderer()->setDepthWrite(true);
1086}
1087
1089{
1090 // At exit use any other projection.
1091 Director::getInstance()->setProjection(Director::Projection::DEFAULT);
1092 Director::getInstance()->getRenderer()->setDepthTest(false);
1093 Director::getInstance()->getRenderer()->setDepthWrite(false);
1094
1096}
1097
1098std::string TMXIsoVertexZ::title() const
1099{
1100 return "TMX Iso VertexZ";
1101}
1102
1103std::string TMXIsoVertexZ::subtitle() const
1104{
1105 return "Sprite should hide behind the trees";
1106}
1107
1108
1109//------------------------------------------------------------------
1110//
1111// TMXOrthoVertexZ
1112//
1113//------------------------------------------------------------------
1115{
1116 auto map = TMXTiledMap::create("TileMaps/orthogonal-test-vertexz.tmx");
1117 addChild(map, 0, kTagTileMap);
1118
1119 Size CC_UNUSED s = map->getContentSize();
1120 CCLOG("ContentSize: %f, %f", s.width,s.height);
1121
1122 // because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you
1123 // can use any Sprite and it will work OK.
1124 auto layer = map->getLayer("trees");
1125 _tamara = layer->getTileAt(Vec2(0,11));
1126 CCLOG("%p vertexZ: %f", _tamara, _tamara->getPositionZ());
1127 _tamara->retain();
1128
1129 auto move = MoveBy::create(10, Vec2(400,450) * (1/CC_CONTENT_SCALE_FACTOR()));
1130 auto back = move->reverse();
1131 auto seq = Sequence::create(move, back,nullptr);
1132 _tamara->runAction( RepeatForever::create(seq));
1133
1134 schedule(CC_SCHEDULE_SELECTOR(TMXOrthoVertexZ::repositionSprite));
1135
1136}
1137
1139{
1140 _tamara->release();
1141}
1142
1144{
1145 // tile height is 101x81
1146 // map size: 12x12
1147 auto p = _tamara->getPosition();
1148 p = CC_POINT_POINTS_TO_PIXELS(p);
1149 _tamara->setPositionZ( -( (p.y+81) /81) );
1150}
1151
1153{
1155
1156 // TIP: 2d projection should be used
1157 Director::getInstance()->setProjection(Director::Projection::_2D);
1158 Director::getInstance()->getRenderer()->setDepthTest(true);
1159 Director::getInstance()->getRenderer()->setDepthWrite(true);
1160
1161}
1162
1164{
1165 // At exit use any other projection.
1166 Director::getInstance()->setProjection(Director::Projection::DEFAULT);
1167 Director::getInstance()->getRenderer()->setDepthTest(false);
1168 Director::getInstance()->getRenderer()->setDepthWrite(false);
1170}
1171
1172std::string TMXOrthoVertexZ::title() const
1173{
1174 return "TMX Ortho vertexZ";
1175}
1176
1177std::string TMXOrthoVertexZ::subtitle() const
1178{
1179 return "Sprite should hide behind the trees";
1180}
1181
1182
1183//------------------------------------------------------------------
1184//
1185// TMXIsoMoveLayer
1186//
1187//------------------------------------------------------------------
1189{
1190 auto map = TMXTiledMap::create("TileMaps/iso-test-movelayer.tmx");
1191 addChild(map, 0, kTagTileMap);
1192
1193 map->setPosition(Vec2(-700.0f,-50.0f));
1194
1195 Size CC_UNUSED s = map->getContentSize();
1196 CCLOG("ContentSize: %f, %f", s.width,s.height);
1197}
1198
1199std::string TMXIsoMoveLayer::title() const
1200{
1201 return "TMX Iso Move Layer";
1202}
1203
1204std::string TMXIsoMoveLayer::subtitle() const
1205{
1206 return "Trees should be horizontally aligned";
1207}
1208
1209
1210//------------------------------------------------------------------
1211//
1212// TMXOrthoMoveLayer
1213//
1214//------------------------------------------------------------------
1216{
1217 auto map = TMXTiledMap::create("TileMaps/orthogonal-test-movelayer.tmx");
1218 addChild(map, 0, kTagTileMap);
1219
1220 Size CC_UNUSED s = map->getContentSize();
1221 CCLOG("ContentSize: %f, %f", s.width,s.height);
1222}
1223
1224std::string TMXOrthoMoveLayer::title() const
1225{
1226 return "TMX Ortho Move Layer";
1227}
1228
1230{
1231 return "Trees should be horizontally aligned";
1232}
1233
1234//------------------------------------------------------------------
1235//
1236// TMXTilePropertyTest
1237//
1238//------------------------------------------------------------------
1239
1241{
1242 auto map = TMXTiledMap::create("TileMaps/ortho-tile-property.tmx");
1243 addChild(map ,0 ,kTagTileMap);
1244
1245 for(int i=1;i<=20;i++){
1246 for(const auto& value : map->getPropertiesForGID(i).asValueMap())
1247 {
1248 log("GID:%i, Properties:%s, %s", i, value.first.c_str(), value.second.asString().c_str());
1249 }
1250 }
1251}
1252
1254{
1255 return "TMX Tile Property Test";
1256}
1257
1259{
1260 return "In the console you should see tile properties";
1261}
1262
1263//------------------------------------------------------------------
1264//
1265// TMXOrthoFlipTest
1266//
1267//------------------------------------------------------------------
1268
1270{
1271 auto map = TMXTiledMap::create("TileMaps/ortho-rotation-test.tmx");
1272 addChild(map, 0, kTagTileMap);
1273
1274 Size CC_UNUSED s = map->getContentSize();
1275 log("ContentSize: %f, %f", s.width,s.height);
1276
1277 auto& children = map->getChildren();
1278 for(const auto &node : children) {
1279 auto child = static_cast<SpriteBatchNode*>(node);
1280 child->getTexture()->setAntiAliasTexParameters();
1281 }
1282
1283 auto action = ScaleBy::create(2, 0.5f);
1284 map->runAction(action);
1285}
1286
1287std::string TMXOrthoFlipTest::title() const
1288{
1289 return "TMX tile flip test";
1290}
1291
1292//------------------------------------------------------------------
1293//
1294// TMXOrthoFlipRunTimeTest
1295//
1296//------------------------------------------------------------------
1297
1299{
1300 auto map = TMXTiledMap::create("TileMaps/ortho-rotation-test.tmx");
1301 addChild(map, 0, kTagTileMap);
1302
1303 auto s = map->getContentSize();
1304 log("ContentSize: %f, %f", s.width,s.height);
1305
1306 auto& children = map->getChildren();
1307 for(const auto &node : children) {
1308 auto child = static_cast<SpriteBatchNode*>(node);
1309 child->getTexture()->setAntiAliasTexParameters();
1310 }
1311
1312 auto action = ScaleBy::create(2, 0.5f);
1313 map->runAction(action);
1314
1315 schedule(CC_SCHEDULE_SELECTOR(TMXOrthoFlipRunTimeTest::flipIt), 1.0f);
1316}
1317
1319{
1320 return "TMX tile flip run time test";
1321}
1322
1324{
1325 return "in 2 sec bottom left tiles will flip";
1326}
1327
1329{
1330 auto map = (TMXTiledMap*) getChildByTag(kTagTileMap);
1331 auto layer = map->getLayer("Layer 0");
1332
1333 //blue diamond
1334 auto tileCoord = Vec2(1,10);
1335 int flags;
1336 unsigned int GID = layer->getTileGIDAt(tileCoord, (TMXTileFlags*)&flags);
1337 // Vertical
1338 if( flags & kTMXTileVerticalFlag )
1339 flags &= ~kTMXTileVerticalFlag;
1340 else
1341 flags |= kTMXTileVerticalFlag;
1342 layer->setTileGID(GID ,tileCoord, (TMXTileFlags)flags);
1343
1344
1345 tileCoord = Vec2(1,8);
1346 GID = layer->getTileGIDAt(tileCoord, (TMXTileFlags*)&flags);
1347 // Vertical
1348 if( flags & kTMXTileVerticalFlag )
1349 flags &= ~kTMXTileVerticalFlag;
1350 else
1351 flags |= kTMXTileVerticalFlag;
1352 layer->setTileGID(GID ,tileCoord, (TMXTileFlags)flags);
1353
1354
1355 tileCoord = Vec2(2,8);
1356 GID = layer->getTileGIDAt(tileCoord, (TMXTileFlags*)&flags);
1357 // Horizontal
1358 if( flags & kTMXTileHorizontalFlag )
1359 flags &= ~kTMXTileHorizontalFlag;
1360 else
1361 flags |= kTMXTileHorizontalFlag;
1362 layer->setTileGID(GID, tileCoord, (TMXTileFlags)flags);
1363}
1364//------------------------------------------------------------------
1365//
1366// TMXOrthoFromXMLTest
1367//
1368//------------------------------------------------------------------
1369
1371{
1372 std::string resources = "TileMaps"; // partial paths are OK as resource paths.
1373 std::string file = resources + "/orthogonal-test1.tmx";
1374
1375 auto fileUtils = FileUtils::getInstance();
1376 std::string str = fileUtils->getStringFromFile(fileUtils->fullPathForFilename(file.c_str()));
1377
1378 auto map = TMXTiledMap::createWithXML(str ,resources.c_str());
1379 addChild(map, 0, kTagTileMap);
1380
1381 auto s = map->getContentSize();
1382 log("ContentSize: %f, %f", s.width,s.height);
1383
1384 auto& children = map->getChildren();
1385 for(const auto &node : children) {
1386 auto child = static_cast<SpriteBatchNode*>(node);
1387 child->getTexture()->setAntiAliasTexParameters();
1388 }
1389
1390 auto action = ScaleBy::create(2, 0.5f);
1391 map->runAction(action);
1392}
1393
1395{
1396 return "TMX created from XML test";
1397}
1398//------------------------------------------------------------------
1399//
1400// TMXOrthoXMLFormatTest
1401//
1402//------------------------------------------------------------------
1403
1405{
1406 // this test tests for:
1407 // 1. load xml format tilemap
1408 // 2. gid lower than firstgid is ignored
1409 // 3. firstgid in tsx is ignored, tile property in tsx loaded correctly.
1410 auto map = TMXTiledMap::create("TileMaps/xml-test.tmx");
1411 addChild(map, 0, kTagTileMap);
1412
1413 auto s = map->getContentSize();
1414 log("ContentSize: %f, %f", s.width,s.height);
1415
1416 auto& children = map->getChildren();
1417 for(const auto &node : children) {
1418 auto child = static_cast<SpriteBatchNode*>(node);
1419 child->getTexture()->setAntiAliasTexParameters();
1420 }
1421
1422 for(int i=24;i<=26;i++){
1423 log("GID:%i, Properties:%s", i, map->getPropertiesForGID(i).asValueMap()["name"].asString().c_str());
1424 }
1425
1426 auto action = ScaleBy::create(2, 0.5f);
1427 map->runAction(action);
1428}
1429
1431{
1432 return "you should see blue, green and yellow in console.";
1433}
1434
1435//------------------------------------------------------------------
1436//
1437// TMXBug987
1438//
1439//------------------------------------------------------------------
1441{
1442 auto map = TMXTiledMap::create("TileMaps/orthogonal-test6.tmx");
1443 addChild(map, 0, kTagTileMap);
1444
1445 Size CC_UNUSED s1 = map->getContentSize();
1446 CCLOG("ContentSize: %f, %f", s1.width,s1.height);
1447
1448 auto& children = map->getChildren();
1449 for(const auto &child : children) {
1450 auto node = static_cast<TMXLayer*>(child);
1451 node->getTexture()->setAntiAliasTexParameters();
1452 }
1453
1454 map->setAnchorPoint(Vec2(0.0f, 0.0f));
1455 auto layer = map->getLayer("Tile Layer 1");
1456 layer->setTileGID(3, Vec2(2.0f,2.0f));
1457}
1458
1459std::string TMXBug987::title() const
1460{
1461 return "TMX Bug 987";
1462}
1463
1464std::string TMXBug987::subtitle() const
1465{
1466 return "You should see an square";
1467}
1468
1469//------------------------------------------------------------------
1470//
1471// TMXBug787
1472//
1473//------------------------------------------------------------------
1475{
1476 auto map = TMXTiledMap::create("TileMaps/iso-test-bug787.tmx");
1477 addChild(map, 0, kTagTileMap);
1478
1479 map->setScale(0.25f);
1480}
1481
1482std::string TMXBug787::title() const
1483{
1484 return "TMX Bug 787";
1485}
1486
1487std::string TMXBug787::subtitle() const
1488{
1489 return "You should see a map";
1490}
1491
1492//------------------------------------------------------------------
1493//
1494// TMXGIDObjectsTest
1495//
1496//------------------------------------------------------------------
1498{
1499 auto map = TMXTiledMap::create("TileMaps/test-object-layer.tmx");
1500 addChild(map, -1, kTagTileMap);
1501
1502 Size CC_UNUSED s = map->getContentSize();
1503 CCLOG("Contentsize: %f, %f", s.width, s.height);
1504
1505 CCLOG("----> Iterating over all the group objects");
1506
1507 auto drawNode = DrawNode::create();
1508 Color4F color(1.0, 1.0, 1.0, 1.0);
1509 auto group = map->getObjectGroup("Object Layer 1");
1510 auto& objects = group->getObjects();
1511 for (auto& obj : objects)
1512 {
1513 ValueMap& dict = obj.asValueMap();
1514
1515 float x = dict["x"].asFloat();
1516 float y = dict["y"].asFloat();
1517 float width = dict["width"].asFloat();
1518 float height = dict["height"].asFloat();
1519
1520 drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color);
1521 drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color);
1522 drawNode->drawLine(Vec2(x + width,y + height), Vec2(x,y + height), color);
1523 drawNode->drawLine(Vec2(x,y + height), Vec2(x,y), color);
1524 }
1525 map->addChild(drawNode);
1526}
1527
1528std::string TMXGIDObjectsTest::title() const
1529{
1530 return "TMX GID objects";
1531}
1532
1534{
1535 return "Tiles are created from an object group";
1536}
1537
1538//------------------------------------------------------------------
1539//
1540// TMXHexOddXTest
1541//
1542//------------------------------------------------------------------
1544{
1545 auto color = LayerColor::create( Color4B(64,64,64,255) );
1546 addChild(color, -1);
1547
1548 auto map = TMXTiledMap::create("TileMaps/hexagonal-mini-odd-x.tmx");
1549 addChild(map, 0, kTagTileMap);
1550
1551 Size CC_UNUSED s = map->getContentSize();
1552 CCLOG("ContentSize: %f, %f", s.width,s.height);
1553
1554 // Testing issue 16512 as well. Should not crash
1555 auto floor = map->getLayer("Ground");
1556 for (auto x = 0; x < map->getMapSize().width; x++) {
1557 for (auto y = 0; y < map->getMapSize().height; y++) {
1558 Vec2 p(x, y);
1559 floor->getTileAt(p);
1560 }
1561 }
1562}
1563
1564std::string TMXHexOddXTest::title() const
1565{
1566 return "TMX Hex Odd X";
1567}
1568
1569//------------------------------------------------------------------
1570//
1571// TMXHexOddYTest
1572//
1573//------------------------------------------------------------------
1575{
1576 auto color = LayerColor::create( Color4B(64,64,64,255) );
1577 addChild(color, -1);
1578
1579 auto map = TMXTiledMap::create("TileMaps/hexagonal-mini-odd-y.tmx");
1580 addChild(map, 0, kTagTileMap);
1581
1582 Size CC_UNUSED s = map->getContentSize();
1583 CCLOG("ContentSize: %f, %f", s.width,s.height);
1584
1585 // Testing issue 16512 as well. Should not crash
1586 auto floor = map->getLayer("Ground");
1587 for (auto x = 0; x < map->getMapSize().width; x++) {
1588 for (auto y = 0; y < map->getMapSize().height; y++) {
1589 Vec2 p(x, y);
1590 floor->getTileAt(p);
1591 }
1592 }
1593}
1594
1595std::string TMXHexOddYTest::title() const
1596{
1597 return "TMX Hex Odd Y";
1598}
1599
1600//------------------------------------------------------------------
1601//
1602// TMXHexEvenXTest
1603//
1604//------------------------------------------------------------------
1606{
1607 auto color = LayerColor::create( Color4B(64,64,64,255) );
1608 addChild(color, -1);
1609
1610 auto map = TMXTiledMap::create("TileMaps/hexagonal-mini-even-x.tmx");
1611 addChild(map, 0, kTagTileMap);
1612
1613 Size CC_UNUSED s = map->getContentSize();
1614 CCLOG("ContentSize: %f, %f", s.width,s.height);
1615
1616 // Testing issue 16512 as well. Should not crash
1617 auto floor = map->getLayer("Ground");
1618 for (auto x = 0; x < map->getMapSize().width; x++) {
1619 for (auto y = 0; y < map->getMapSize().height; y++) {
1620 Vec2 p(x, y);
1621 floor->getTileAt(p);
1622 }
1623 }
1624}
1625
1626std::string TMXHexEvenXTest::title() const
1627{
1628 return "TMX Hex Even X";
1629}
1630
1631//------------------------------------------------------------------
1632//
1633// TMXHexEvenYTest
1634//
1635//------------------------------------------------------------------
1637{
1638 auto color = LayerColor::create( Color4B(64,64,64,255) );
1639 addChild(color, -1);
1640
1641 auto map = TMXTiledMap::create("TileMaps/hexagonal-mini-even-y.tmx");
1642 addChild(map, 0, kTagTileMap);
1643
1644 Size CC_UNUSED s = map->getContentSize();
1645 CCLOG("ContentSize: %f, %f", s.width,s.height);
1646
1647 // Testing issue 16512 as well. Should not crash
1648 auto floor = map->getLayer("Ground");
1649 for (auto x = 0; x < map->getMapSize().width; x++) {
1650 for (auto y = 0; y < map->getMapSize().height; y++) {
1651 Vec2 p(x, y);
1652 floor->getTileAt(p);
1653 }
1654 }
1655}
1656
1657std::string TMXHexEvenYTest::title() const
1658{
1659 return "TMX Hex Even Y";
1660}
1661
1662//------------------------------------------------------------------
1663//
1664// TMXHexAxisXTest
1665//
1666//------------------------------------------------------------------
1668{
1669 auto color = LayerColor::create( Color4B(64,64,64,255) );
1670 addChild(color, -1);
1671
1672 auto map = TMXTiledMap::create("TileMaps/hexa-axis-x.tmx");
1673 addChild(map, 0, kTagTileMap);
1674
1675 Size CC_UNUSED s = map->getContentSize();
1676 CCLOG("ContentSize: %f, %f", s.width,s.height);
1677}
1678
1679std::string TMXHexAxisXTest::title() const
1680{
1681 return "The map should be same with in Tiled Editor";
1682}
1683
1684//------------------------------------------------------------------
1685//
1686// Issue16105Test
1687//
1688//------------------------------------------------------------------
1690{
1691 auto color = LayerColor::create( Color4B(64,64,64,255) );
1692 addChild(color, -1);
1693
1694 auto map = TMXTiledMap::create("TileMaps/issue16105.tmx");
1695 addChild(map, 0, kTagTileMap);
1696
1697 Size CC_UNUSED s = map->getContentSize();
1698 CCLOG("ContentSize: %f, %f", s.width,s.height);
1699}
1700
1701std::string Issue16105Test::title() const
1702{
1703 return "Github Issue #16105";
1704}
1705
1706//------------------------------------------------------------------
1707//
1708// Issue16512Test
1709//
1710//------------------------------------------------------------------
1712{
1713 auto color = LayerColor::create( Color4B(64,64,64,255) );
1714 addChild(color, -1);
1715
1716 auto map = TMXTiledMap::create("TileMaps/issue_16512.tmx");
1717 addChild(map, 0, kTagTileMap);
1718
1719 Size CC_UNUSED s = map->getContentSize();
1720 CCLOG("ContentSize: %f, %f", s.width,s.height);
1721
1722 auto floor = map->getLayer("Floor");
1723 for (auto x = 0; x < map->getMapSize().width; x++) {
1724 for (auto y = 0; y < map->getMapSize().height; y++) {
1725 Vec2 p(x, y);
1726 floor->getTileAt(p);
1727 }
1728 }
1729}
1730
1731std::string Issue16512Test::title() const
1732{
1733 return "Github Issue #16512. Should not crash";
1734}
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
@ kTagTileMap
Definition: TileMapTest.cpp:33
@ SID_UPDATECOL
@ SID_REMOVETILES
@ SID_REPAINTWITHGID
USING_NS_CC
Definition: TileMapTest.cpp:29
virtual std::string title() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string title() const override
virtual void onExit() override
virtual std::string title() const override
virtual void onEnter() override
virtual std::string subtitle() const override
void repositionSprite(float dt)
cocos2d::Sprite * _tamara
Definition: TileMapTest.h:240
virtual std::string subtitle() const override
virtual std::string title() const override
void repositionSprite(float dt)
cocos2d::Sprite * _tamara
Definition: TileMapTest.h:213
virtual void onExit() override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual std::string title() const override
void removeSprite(float dt)
virtual std::string title() const override
virtual void onExit() override
virtual std::string title() const override
virtual void onEnter() override
virtual void onExit() override
cocos2d::Sprite * _tamara
Definition: TileMapTest.h:255
virtual void onEnter() override
virtual std::string title() const override
void repositionSprite(float dt)
virtual std::string subtitle() const override
virtual std::string title() const override
virtual ~TMXOrthoZorder()
virtual std::string title() const override
void repositionSprite(float dt)
virtual std::string subtitle() const override
cocos2d::Sprite * _tamara
Definition: TileMapTest.h:227
void removeSprite(Node *sender)
void removeTiles(float dt)
unsigned int _gid
Definition: TileMapTest.h:112
void updateCol(float dt)
void repaintWithGID(float dt)
virtual std::string title() const override
unsigned int _gid2
Definition: TileMapTest.h:113
virtual std::string title() const override
virtual std::string subtitle() const override
virtual void onEnter() override
virtual std::string title() const override
virtual void onExit() override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual std::string title() const override
virtual std::string title() const override
virtual void onEnter() override
Definition: BaseTest.cpp:430
void onTouchesMoved(const std::vector< cocos2d::Touch * > &touches, cocos2d::Event *event)
virtual void onExit() override
virtual std::string title() const override
virtual std::string subtitle() const override
virtual ~TileDemo()
Definition: TileMapTest.cpp:99
void updateMap(float dt)
virtual std::string title() const override
virtual std::string title() const override
static const char s_TilesPng[]
Definition: testResource.h:63
static const char s_LevelMapTga[]
Definition: testResource.h:64
static const char s_pathSister1[]
Definition: testResource.h:29