PuzzleSDK
UseCaseSprite3D类 参考

#include <Sprite3DTest.h>

+ 类 UseCaseSprite3D 继承关系图:
+ UseCaseSprite3D 的协作图:

Public 成员函数

 CREATE_FUNC (UseCaseSprite3D)
 
 UseCaseSprite3D ()
 
virtual std::string title () const override
 
virtual std::string subtitle () const override
 
virtual void update (float delta) override
 
void menuCallback_Message (cocos2d::Ref *sender)
 
- Public 成员函数 继承自 Sprite3DTestDemo
virtual ~Sprite3DTestDemo ()
 
- Public 成员函数 继承自 TestCase
 TestCase ()
 
 ~TestCase ()
 
virtual Type getTestType () const
 
virtual float getDuration () const
 
virtual std::string getExpectedOutput () const
 
virtual std::string getActualOutput () const
 
virtual void restartTestCallback (cocos2d::Ref *sender)
 
virtual void nextTestCallback (cocos2d::Ref *sender)
 
virtual void priorTestCallback (cocos2d::Ref *sender)
 
virtual void onBackCallback (cocos2d::Ref *sender)
 
void setTestSuite (TestSuite *testSuite)
 
TestSuitegetTestSuite () const
 
float getRunTime () const
 
void setTestCaseName (const std::string &name)
 
std::string getTestCaseName () const
 
const cocos2d::Label * getSubtitleLable () const
 
const cocos2d::MenuItemImage * getRestartTestItem () const
 
virtual void onEnter () override
 

Protected 类型

enum class  USECASE { _3D_WITH_2D , _UI_3D_UI , MAX_CASE_NUM }
 

Protected 成员函数

void switchCase ()
 

Protected 属性

cocos2d::Label * _label
 
int _caseIdx
 
std::string _useCaseTitles [(int) USECASE::MAX_CASE_NUM]
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 

详细描述

在文件 Sprite3DTest.h416 行定义.

成员枚举类型说明

◆ USECASE

enum class UseCaseSprite3D::USECASE
strongprotected
枚举值
_3D_WITH_2D 
_UI_3D_UI 
MAX_CASE_NUM 

在文件 Sprite3DTest.h432 行定义.

432 {
433 _3D_WITH_2D,
434 _UI_3D_UI,
435 MAX_CASE_NUM,
436 };

构造及析构函数说明

◆ UseCaseSprite3D()

UseCaseSprite3D::UseCaseSprite3D ( )

在文件 Sprite3DTest.cpp1780 行定义.

1781 : _caseIdx(0)
1782{
1783 auto s = Director::getInstance()->getWinSize();
1784
1785 _useCaseTitles[0] = "transparent 3d sprite and 2d sprite";
1786 _useCaseTitles[1] = "ui - 3d - ui";
1787
1788 auto itemPrev = MenuItemImage::create("Images/b1.png", "Images/b2.png",
1789 [&](Ref *sender) {
1790 _caseIdx--;
1791 if (_caseIdx < 0)
1793 this->switchCase();
1794 });
1795
1796 auto itemNext = MenuItemImage::create("Images/f1.png", "Images/f2.png",
1797 [&](Ref *sender) {
1798 _caseIdx++;
1799 if (_caseIdx >= (int)USECASE::MAX_CASE_NUM)
1800 _caseIdx = 0;
1801 this->switchCase();
1802 });
1803
1804 auto menu = Menu::create(itemPrev, itemNext, nullptr);
1805 menu->alignItemsHorizontally();
1806 menu->setScale(0.5);
1807 menu->setAnchorPoint(Vec2(0.0f, 0.0f));
1808 menu->setPosition(Vec2(s.width / 2, 70.0f));
1809
1810 _label = Label::create();
1811 _label->setPosition(s.width * 0.5f, s.height * 0.8f);
1812 addChild(_label);
1813
1814 addChild(menu);
1815
1816 //setup camera
1817 auto camera = Camera::createPerspective(40, s.width / s.height, 0.01f, 1000.f);
1818 camera->setCameraFlag(CameraFlag::USER1);
1819 camera->setPosition3D(Vec3(0.f, 30.f, 100.f));
1820 camera->lookAt(Vec3(0.f, 0.f, 0.f));
1821 addChild(camera);
1822
1823 switchCase();
1824}
cocos2d::Label * _label
Definition: Sprite3DTest.h:437
std::string _useCaseTitles[(int) USECASE::MAX_CASE_NUM]
Definition: Sprite3DTest.h:439

引用了 _caseIdx, _label, _useCaseTitles, MAX_CASE_NUM , 以及 switchCase().

+ 函数调用图:

成员函数说明

◆ CREATE_FUNC()

UseCaseSprite3D::CREATE_FUNC ( UseCaseSprite3D  )

◆ menuCallback_Message()

void UseCaseSprite3D::menuCallback_Message ( cocos2d::Ref *  sender)

在文件 Sprite3DTest.cpp1916 行定义.

1917{
1918 auto layer = getChildByTag(101);
1919 auto message = layer->getChildByTag(102); // message layer
1920 if (message)
1921 layer->removeChild(message);
1922 else
1923 {
1924 // create a new message layer on the top
1925 auto s = layer->getContentSize();
1926 auto messagelayer = LayerColor::create(Color4B(100, 100, 0, 255));
1927 messagelayer->setContentSize(Size(s.width * 0.5f, s.height * 0.5f));
1928 messagelayer->setPosition(Vec2(s.width * 0.25f, s.height * 0.25f));
1929 auto label = Label::create();
1930 label->setString("This Message Layer \n Should Be On Top");
1931 label->setPosition(Vec2(s.width * 0.25f, s.height * 0.25f));
1932 messagelayer->addChild(label);
1933 messagelayer->setTag(102);
1934 layer->addChild(messagelayer);
1935 }
1936}

被这些函数引用 switchCase().

+ 这是这个函数的调用关系图:

◆ subtitle()

std::string UseCaseSprite3D::subtitle ( ) const
overridevirtual

重载 TestCase .

在文件 Sprite3DTest.cpp1831 行定义.

1832{
1833 return "";
1834}

◆ switchCase()

void UseCaseSprite3D::switchCase ( )
protected

在文件 Sprite3DTest.cpp1836 行定义.

1837{
1838 removeChildByTag(101);
1839
1840 auto s = Director::getInstance()->getWinSize();
1841 _label->setString(_useCaseTitles[_caseIdx]);
1842 if (_caseIdx == 0) // use case 1, 3d transparent sprite + 2d sprite
1843 {
1844 std::string filename = "Sprite3DTest/girl.c3b";
1845 auto sprite = Sprite3D::create(filename);
1846 sprite->setScale(0.15f);
1847 auto animation = Animation3D::create(filename);
1848 if (animation)
1849 {
1850 auto animate = Animate3D::create(animation);
1851 sprite->runAction(RepeatForever::create(animate));
1852 }
1853
1854 auto circleBack = Sprite3D::create();
1855 auto circle = Sprite::create("Sprite3DTest/circle.png");
1856 circleBack->setScale(0.5f);
1857 circleBack->addChild(circle);
1858 circle->runAction(RepeatForever::create(RotateBy::create(3, Vec3(0.f, 0.f, 360.f))));
1859
1860 circleBack->setRotation3D(Vec3(-90.0f, -90.0f, 0.0f));
1861
1862 auto pos = sprite->getPosition3D();
1863 circleBack->setPosition3D(Vec3(pos.x, pos.y, pos.z - 1));
1864
1865 sprite->setOpacity(250);
1866 sprite->setCameraMask(2);
1867 circleBack->setCameraMask(2);
1868 sprite->setTag(3);
1869 circleBack->setTag(2);
1870
1871 auto node = Node::create();
1872 node->addChild(sprite);
1873 node->addChild(circleBack);
1874 node->setTag(101);
1875 addChild(node);
1876
1877 scheduleUpdate();
1878 update(0.f);
1879 }
1880 else if (_caseIdx == 1) // use case 2, ui - 3d - ui, last ui should on the top
1881 {
1882 auto layer = LayerColor::create(Color4B(0, 0, 100, 255), s.width / 2.f, s.height / 2.f);
1883 layer->setPosition(s.width * 0.25f, s.height * 0.25f);
1884 layer->setGlobalZOrder(-1);
1885 addChild(layer);
1886
1887 std::string filename = "Sprite3DTest/girl.c3b";
1888 auto sprite = Sprite3D::create(filename);
1889 sprite->setScale(0.5f);
1890 auto animation = Animation3D::create(filename);
1891 if (animation)
1892 {
1893 auto animate = Animate3D::create(animation);
1894 sprite->runAction(RepeatForever::create(animate));
1895 }
1896 sprite->setPosition(s.width * 0.25f, s.height * 0.125f);
1897 layer->addChild(sprite);
1898
1899 TTFConfig ttfConfig("fonts/arial.ttf", 15);
1900 auto label1 = Label::createWithTTF(ttfConfig, "Message");
1901 auto item1 = MenuItemLabel::create(label1, CC_CALLBACK_1(UseCaseSprite3D::menuCallback_Message, this));
1902 auto label2 = Label::createWithTTF(ttfConfig, "Message");
1903 auto item2 = MenuItemLabel::create(label2, CC_CALLBACK_1(UseCaseSprite3D::menuCallback_Message, this));
1904
1905 item1->setPosition(Vec2(s.width * 0.5f - item1->getContentSize().width * 0.5f, s.height * 0.5f - item1->getContentSize().height));
1906 item2->setPosition(Vec2(s.width * 0.5f - item1->getContentSize().width * 0.5f, s.height * 0.5f - item1->getContentSize().height * 2.f));
1907
1908 auto pMenu1 = Menu::create(item1, item2, nullptr);
1909 pMenu1->setPosition(Vec2(0.0f, 0.0f));
1910 layer->addChild(pMenu1);
1911
1912 layer->setTag(101);
1913 }
1914}
virtual void update(float delta) override
void menuCallback_Message(cocos2d::Ref *sender)

引用了 _caseIdx, _label, _useCaseTitles, menuCallback_Message() , 以及 update().

被这些函数引用 UseCaseSprite3D().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ title()

std::string UseCaseSprite3D::title ( ) const
overridevirtual

重载 Sprite3DTestDemo .

在文件 Sprite3DTest.cpp1826 行定义.

1827{
1828 return "Use Case For 2D + 3D";
1829}

◆ update()

void UseCaseSprite3D::update ( float  delta)
overridevirtual

在文件 Sprite3DTest.cpp1938 行定义.

1939{
1940 if (_caseIdx == 0)
1941 {
1942 static float accAngle = 0.f;
1943 accAngle += delta * CC_DEGREES_TO_RADIANS(60);
1944
1945 float radius = 30.f;
1946 float x = cosf(accAngle) * radius, z = sinf(accAngle) * radius;
1947
1948 auto node = getChildByTag(101);
1949 auto sprite3d = node->getChildByTag(3);
1950 auto circle = node->getChildByTag(2);
1951
1952 sprite3d->setPositionX(x);
1953 sprite3d->setPositionZ(z);
1954 circle->setPositionX(x);
1955 circle->setPositionZ(z);
1956 }
1957}

引用了 _caseIdx.

被这些函数引用 switchCase().

+ 这是这个函数的调用关系图:

类成员变量说明

◆ _caseIdx

int UseCaseSprite3D::_caseIdx
protected

在文件 Sprite3DTest.h438 行定义.

被这些函数引用 switchCase(), update() , 以及 UseCaseSprite3D().

◆ _label

cocos2d::Label* UseCaseSprite3D::_label
protected

在文件 Sprite3DTest.h437 行定义.

被这些函数引用 switchCase() , 以及 UseCaseSprite3D().

◆ _useCaseTitles

std::string UseCaseSprite3D::_useCaseTitles[(int) USECASE::MAX_CASE_NUM]
protected

在文件 Sprite3DTest.h439 行定义.

被这些函数引用 switchCase() , 以及 UseCaseSprite3D().


该类的文档由以下文件生成: