PuzzleSDK
SpriteFrameAliasNameTest类 参考

#include <SpriteTest.h>

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

Public 成员函数

 CREATE_FUNC (SpriteFrameAliasNameTest)
 
virtual void onEnter () override
 
virtual void onExit () override
 
virtual std::string title () const override
 
virtual std::string subtitle () const override
 
- 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
 

额外继承的成员函数

- Public 类型 继承自 TestCase
enum class  Type { ROBUSTNESS , UNIT , GRAPHICAL_STATIC , MANUAL }
 
- Public 属性 继承自 TestCase
CC_CONSTRUCTOR_ACCESS __pad0__: virtual bool init() override
 
- Protected 属性 继承自 SpriteTestDemo
std::string _title
 
- Protected 属性 继承自 TestCase
cocos2d::MenuItemImage * _priorTestItem
 
cocos2d::MenuItemImage * _restartTestItem
 
cocos2d::MenuItemImage * _nextTestItem
 
cocos2d::Label * _titleLabel
 
cocos2d::Label * _subtitleLabel
 

详细描述

在文件 SpriteTest.h346 行定义.

成员函数说明

◆ CREATE_FUNC()

SpriteFrameAliasNameTest::CREATE_FUNC ( SpriteFrameAliasNameTest  )

◆ onEnter()

void SpriteFrameAliasNameTest::onEnter ( )
overridevirtual

重载 TestCase .

在文件 SpriteTest.cpp1883 行定义.

1884{
1886 auto s = Director::getInstance()->getWinSize();
1887
1888 // IMPORTANT:
1889 // The sprite frames will be cached AND RETAINED, and they won't be released unless you call
1890 // SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
1891 //
1892 // SpriteFrameCache is a cache of SpriteFrames
1893 // SpriteFrames each contain a texture id and a rect (frame).
1894
1895 auto cache = SpriteFrameCache::getInstance();
1896 cache->addSpriteFramesWithFile("animations/grossini-aliases.plist", "animations/grossini-aliases.png");
1897
1898 //
1899 // Animation using Sprite batch
1900 //
1901 // A SpriteBatchNode can reference one and only one texture (one .png file)
1902 // Sprites that are contained in that texture can be instantiated as Sprites and then added to the SpriteBatchNode
1903 // All Sprites added to a SpriteBatchNode are drawn in one OpenGL ES draw call
1904 // If the Sprites are not added to a SpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient
1905 //
1906 // When you animate a sprite, Animation changes the frame of the sprite using setDisplayFrame: (this is why the animation must be in the same texture)
1907 // When setDisplayFrame: is used in the Animation it changes the frame to one specified by the SpriteFrames that were added to the animation,
1908 // but texture id is still the same and so the sprite is still a child of the SpriteBatchNode,
1909 // and therefore all the animation sprites are also drawn as part of the SpriteBatchNode
1910 //
1911
1912 auto sprite = Sprite::createWithSpriteFrameName("grossini_dance_01.png");
1913 sprite->setPosition(Vec2(s.width * 0.5f, s.height * 0.5f));
1914
1915 auto spriteBatch = SpriteBatchNode::create("animations/grossini-aliases.png");
1916 spriteBatch->addChild(sprite);
1917 addChild(spriteBatch);
1918
1919 Vector<SpriteFrame*> animFrames(15);
1920 char str[100] = {0};
1921 for(int i = 1; i < 15; i++)
1922 {
1923 // Obtain frames by alias name
1924 sprintf(str, "dance_%02d", i);
1925 auto frame = cache->getSpriteFrameByName(str);
1926 animFrames.pushBack(frame);
1927 }
1928
1929 auto animation = Animation::createWithSpriteFrames(animFrames, 0.3f);
1930 // 14 frames * 1sec = 14 seconds
1931 sprite->runAction(RepeatForever::create(Animate::create(animation)));
1932
1933 cache->reloadTexture("animations/grossini-aliases.plist");
1934}
virtual void onEnter() override
Definition: BaseTest.cpp:430

引用了 TestCase::onEnter().

+ 函数调用图:

◆ onExit()

void SpriteFrameAliasNameTest::onExit ( )
overridevirtual

在文件 SpriteTest.cpp1936 行定义.

1937{
1938 SpriteTestDemo::onExit();
1939 SpriteFrameCache::getInstance()->removeSpriteFramesFromFile("animations/grossini-aliases.plist");
1940}

◆ subtitle()

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

重载 TestCase .

在文件 SpriteTest.cpp1947 行定义.

1948{
1949 return "SpriteFrames are obtained using the alias name";
1950}

◆ title()

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

重载 TestCase .

在文件 SpriteTest.cpp1942 行定义.

1943{
1944 return "SpriteFrame Alias Name";
1945}

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