PuzzleSDK
ShaderRetroEffect类 参考

#include <ShaderTest.h>

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

Public 成员函数

 CREATE_FUNC (ShaderRetroEffect)
 
 ShaderRetroEffect ()
 
virtual std::string title () const override
 
virtual std::string subtitle () const override
 
virtual bool init () override
 
virtual void update (float dt) 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
 
virtual void onEnter () override
 

Protected 属性

cocos2d::Label * _label
 
float _accum
 
- 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
 

详细描述

在文件 ShaderTest.h124 行定义.

构造及析构函数说明

◆ ShaderRetroEffect()

ShaderRetroEffect::ShaderRetroEffect ( )

在文件 ShaderTest.cpp596 行定义.

597: _label(nullptr)
598, _accum(0.0f)
599{
600}
cocos2d::Label * _label
Definition: ShaderTest.h:134

成员函数说明

◆ CREATE_FUNC()

ShaderRetroEffect::CREATE_FUNC ( ShaderRetroEffect  )

◆ init()

bool ShaderRetroEffect::init ( )
overridevirtual

在文件 ShaderTest.cpp602 行定义.

603{
604 if( ShaderTestDemo::init() ) {
605
606 auto fragStr = FileUtils::getInstance()->getStringFromFile(FileUtils::getInstance()->fullPathForFilename("Shaders/example_HorizontalColor.fsh"));
607 char * fragSource = (char*)fragStr.c_str();
608
609 auto program = backend::Device::getInstance()->newProgram(positionTextureColor_vert, fragSource);
610 auto p = new backend::ProgramState(program);
611 auto director = Director::getInstance();
612 const auto& screenSizeLocation = p->getUniformLocation("u_screenSize");
613 const auto& frameSize = director->getOpenGLView()->getFrameSize();
614 float retinaFactor = director->getOpenGLView()->getRetinaFactor();
615 auto screenSizeInPixels = frameSize * retinaFactor;
616 p->setUniform(screenSizeLocation, &screenSizeInPixels, sizeof(screenSizeInPixels));
617
618 auto s = director->getWinSize();
619
620 _label = Label::createWithBMFont("fonts/west_england-64.fnt","RETRO EFFECT");
621 _label->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
622 _label->setProgramState(p);
623 CC_SAFE_RELEASE(p);
624
625 _label->setPosition(Vec2(s.width/2,s.height/2));
626
627 addChild(_label);
628
629 scheduleUpdate();
630 CC_SAFE_RELEASE(program);
631 return true;
632 }
633
634 return false;
635}

引用了 _label.

◆ subtitle()

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

重载 TestCase .

在文件 ShaderTest.cpp662 行定义.

663{
664 return "sin() effect with moving colors";
665}

◆ title()

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

重载 TestCase .

在文件 ShaderTest.cpp657 行定义.

658{
659 return "Shader: Retro test";
660}

◆ update()

void ShaderRetroEffect::update ( float  dt)
overridevirtual

在文件 ShaderTest.cpp637 行定义.

638{
639 _accum += dt;
640 int letterCount = _label->getStringLength();
641 for (int i = 0; i < letterCount; ++i)
642 {
643 auto sprite = _label->getLetter(i);
644 if (sprite != nullptr)
645 {
646 auto oldPosition = sprite->getPosition();
647 sprite->setPosition(Vec2( oldPosition.x, sinf( _accum * 2 + i/2.0) * 20 ));
648
649 // add fabs() to prevent negative scaling
650 float scaleY = ( sinf( _accum * 2 + i/2.0 + 0.707) );
651
652 sprite->setScaleY(scaleY);
653 }
654 }
655}

引用了 _accum , 以及 _label.

类成员变量说明

◆ _accum

float ShaderRetroEffect::_accum
protected

在文件 ShaderTest.h135 行定义.

被这些函数引用 update().

◆ _label

cocos2d::Label* ShaderRetroEffect::_label
protected

在文件 ShaderTest.h134 行定义.

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


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