diff --git a/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.cpp b/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.cpp index 618e421bf6..27a061953a 100644 --- a/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.cpp +++ b/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.cpp @@ -20,6 +20,7 @@ SpritePolygonTest::SpritePolygonTest() ADD_TEST_CASE(SpritePolygonTestTPIsland); ADD_TEST_CASE(SpritePolygonTestAutoPolyIsland); ADD_TEST_CASE(SpritePolygonTestFrameAnim); + ADD_TEST_CASE(Issue14017Test); } SpritePolygonTestCase::SpritePolygonTestCase() @@ -781,3 +782,60 @@ void SpritePolygonTestFrameAnim::initSprites() sprite->runAction(RepeatForever::create(Animate::create(animation))); } + +// +// Issue14017Test +// +Issue14017Test::Issue14017Test() +{ + _title = "Issue 14017"; + _subtitle = "Autopolygon around the banana"; +} + +void Issue14017Test::initSprites() +{ + auto s = Director::getInstance()->getWinSize(); + auto offset = Vec2(0.15*s.width,0); + auto filename = "Images/bug14017.png"; + + //Sprite + auto pinfo = AutoPolygon::generatePolygon(filename); + _polygonSprite = Sprite::create(pinfo); + _polygonSprite->setTag(101); + addChild(_polygonSprite); + _polygonSprite->setPosition(Vec2(s)/2 + offset); + + _normalSprite = Sprite::create(filename); + _normalSprite->setTag(100); + addChild(_normalSprite); + _normalSprite->setPosition(Vec2(s)/2 - offset); + + //DrawNode + auto spDrawNode = DrawNode::create(); + spDrawNode->setTag(_normalSprite->getTag()); + spDrawNode->clear(); + _normalSprite->addChild(spDrawNode); + _drawNodes.pushBack(spDrawNode); + + auto sppDrawNode = DrawNode::create(); + sppDrawNode->setTag(_polygonSprite->getTag()); + sppDrawNode->clear(); + _polygonSprite->addChild(sppDrawNode); + _drawNodes.pushBack(sppDrawNode); + + //Label + TTFConfig ttfConfig("fonts/arial.ttf", 8); + std::string temp = "Sprite:\nPixels drawn: "; + auto spSize = _normalSprite->getContentSize(); + auto spArea = Label::createWithTTF(ttfConfig, temp+Value((int)spSize.width*(int)spSize.height).asString()); + _normalSprite->addChild(spArea); + spArea->setAnchorPoint(Vec2(0,1)); + + temp = "SpritePolygon:\nPixels drawn: "; + auto vertCount = "\nverts:"+Value((int)pinfo.getVertCount()).asString(); + auto sppArea = Label::createWithTTF(ttfConfig, temp+Value((int)pinfo.getArea()).asString()+vertCount); + _polygonSprite->addChild(sppArea); + sppArea->setAnchorPoint(Vec2(0,1)); + + updateDrawNode(); +} diff --git a/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.h b/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.h index 980f22d686..2e4e0a3ba9 100644 --- a/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.h +++ b/tests/cpp-tests/Classes/SpritePolygonTest/SpritePolygonTest.h @@ -185,4 +185,12 @@ public: virtual void initSprites() override; }; +class Issue14017Test : public SpritePolygonTestDemo +{ +public: + CREATE_FUNC(Issue14017Test); + Issue14017Test(); + virtual void initSprites() override; +}; + #endif /* defined(__cocos2d_tests__SpritePolygonTest__) */ diff --git a/tests/cpp-tests/Resources/Images/bug14017.png b/tests/cpp-tests/Resources/Images/bug14017.png new file mode 100644 index 0000000000..824be98da7 Binary files /dev/null and b/tests/cpp-tests/Resources/Images/bug14017.png differ