PuzzleSDK
StopPropagationTest类 参考

#include <NewEventDispatcherTest.h>

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

Public 成员函数

 CREATE_FUNC (StopPropagationTest)
 
 StopPropagationTest ()
 
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
 
virtual void onEnter () override
 

Protected 成员函数

bool isPointInNode (cocos2d::Vec2 pt, cocos2d::Node *node)
 
bool isPointInTopHalfAreaOfScreen (cocos2d::Vec2 pt)
 

额外继承的成员函数

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

详细描述

在文件 NewEventDispatcherTest.h168 行定义.

构造及析构函数说明

◆ StopPropagationTest()

StopPropagationTest::StopPropagationTest ( )

在文件 NewEventDispatcherTest.cpp922 行定义.

923{
924 static const int TAG_BLUE_SPRITE = 101;
925 static const int TAG_BLUE_SPRITE2 = 102;
926
927 auto touchOneByOneListener = EventListenerTouchOneByOne::create();
928 touchOneByOneListener->setSwallowTouches(true);
929
930 touchOneByOneListener->onTouchBegan = [=](Touch* touch, Event* event){
931 // Skip if don't touch top half screen.
932 if (!this->isPointInTopHalfAreaOfScreen(touch->getLocation()))
933 return false;
934
935 auto target = static_cast<Sprite*>(event->getCurrentTarget());
936 CCASSERT(target->getTag() == TAG_BLUE_SPRITE, "Yellow blocks shouldn't response event.");
937
938 if (this->isPointInNode(touch->getLocation(), target))
939 {
940 target->setOpacity(180);
941 return true;
942 }
943
944 // Stop propagation, so yellow blocks will not be able to receive event.
945 event->stopPropagation();
946 return false;
947 };
948
949 touchOneByOneListener->onTouchEnded = [=](Touch* touch, Event* event){
950 auto target = static_cast<Sprite*>(event->getCurrentTarget());
951 target->setOpacity(255);
952 };
953
954 auto touchAllAtOnceListener = EventListenerTouchAllAtOnce::create();
955 touchAllAtOnceListener->onTouchesBegan = [=](const std::vector<Touch*>& touches, Event* event){
956 // Skip if don't touch top half screen.
957 if (this->isPointInTopHalfAreaOfScreen(touches[0]->getLocation()))
958 return;
959
960 auto target = static_cast<Sprite*>(event->getCurrentTarget());
961 CCASSERT(target->getTag() == TAG_BLUE_SPRITE2, "Yellow blocks shouldn't response event.");
962
963 if (this->isPointInNode(touches[0]->getLocation(), target))
964 {
965 target->setOpacity(180);
966 }
967 // Stop propagation, so yellow blocks will not be able to receive event.
968 event->stopPropagation();
969 };
970
971 touchAllAtOnceListener->onTouchesEnded = [=](const std::vector<Touch*>& touches, Event* event){
972 // Skip if don't touch top half screen.
973 if (this->isPointInTopHalfAreaOfScreen(touches[0]->getLocation()))
974 return;
975
976 auto target = static_cast<Sprite*>(event->getCurrentTarget());
977 CCASSERT(target->getTag() == TAG_BLUE_SPRITE2, "Yellow blocks shouldn't response event.");
978
979 if (this->isPointInNode(touches[0]->getLocation(), target))
980 {
981 target->setOpacity(255);
982 }
983 // Stop propagation, so yellow blocks will not be able to receive event.
984 event->stopPropagation();
985 };
986
987 auto keyboardEventListener = EventListenerKeyboard::create();
988 keyboardEventListener->onKeyPressed = [](EventKeyboard::KeyCode /*key*/, Event* event){
989 auto target = static_cast<Sprite*>(event->getCurrentTarget());
990 CC_UNUSED_PARAM(target);
991 CCASSERT(target->getTag() == TAG_BLUE_SPRITE || target->getTag() == TAG_BLUE_SPRITE2, "Yellow blocks shouldn't response event.");
992 // Stop propagation, so yellow blocks will not be able to receive event.
993 event->stopPropagation();
994 };
995
996 const int SPRITE_COUNT = 8;
997
998 for (int i = 0; i < SPRITE_COUNT; i++)
999 {
1000 Sprite* sprite;
1001 Sprite* sprite2;
1002
1003 if(i==4)
1004 {
1005 sprite = Sprite::create("Images/CyanSquare.png");
1006 sprite->setTag(TAG_BLUE_SPRITE);
1007 addChild(sprite, 100);
1008
1009 sprite2 = Sprite::create("Images/CyanSquare.png");
1010 sprite2->setTag(TAG_BLUE_SPRITE2);
1011 addChild(sprite2, 100);
1012 }
1013 else
1014 {
1015 sprite = Sprite::create("Images/YellowSquare.png");
1016 addChild(sprite, 0);
1017 sprite2 = Sprite::create("Images/YellowSquare.png");
1018 addChild(sprite2, 0);
1019 }
1020
1021 _eventDispatcher->addEventListenerWithSceneGraphPriority(touchOneByOneListener->clone(), sprite);
1022 _eventDispatcher->addEventListenerWithSceneGraphPriority(keyboardEventListener->clone(), sprite);
1023
1024 _eventDispatcher->addEventListenerWithSceneGraphPriority(touchAllAtOnceListener->clone(), sprite2);
1025 _eventDispatcher->addEventListenerWithSceneGraphPriority(keyboardEventListener->clone(), sprite2);
1026
1027
1028 Size visibleSize = Director::getInstance()->getVisibleSize();
1029 sprite->setPosition(VisibleRect::left().x + visibleSize.width / (SPRITE_COUNT - 1) * i, VisibleRect::center().y + sprite2->getContentSize().height/2 +10);
1030 sprite2->setPosition(VisibleRect::left().x + visibleSize.width / (SPRITE_COUNT - 1) * i, VisibleRect::center().y - sprite2->getContentSize().height/2-10);
1031 }
1032}
bool isPointInTopHalfAreaOfScreen(cocos2d::Vec2 pt)
bool isPointInNode(cocos2d::Vec2 pt, cocos2d::Node *node)
static cocos2d::Vec2 center()
Definition: VisibleRect.cpp:69
static cocos2d::Vec2 left()
Definition: VisibleRect.cpp:45

引用了 VisibleRect::center(), isPointInNode(), isPointInTopHalfAreaOfScreen() , 以及 VisibleRect::left().

+ 函数调用图:

成员函数说明

◆ CREATE_FUNC()

StopPropagationTest::CREATE_FUNC ( StopPropagationTest  )

◆ isPointInNode()

bool StopPropagationTest::isPointInNode ( cocos2d::Vec2  pt,
cocos2d::Node *  node 
)
protected

在文件 NewEventDispatcherTest.cpp1034 行定义.

1035{
1036 Vec2 locationInNode = node->convertToNodeSpace(pt);
1037 Size s = node->getContentSize();
1038 Rect rect = Rect(0, 0, s.width, s.height);
1039
1040 if (rect.containsPoint(locationInNode))
1041 {
1042 return true;
1043 }
1044 return false;
1045}

被这些函数引用 StopPropagationTest().

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

◆ isPointInTopHalfAreaOfScreen()

bool StopPropagationTest::isPointInTopHalfAreaOfScreen ( cocos2d::Vec2  pt)
protected

在文件 NewEventDispatcherTest.cpp1047 行定义.

1048{
1049 Size winSize = Director::getInstance()->getWinSize();
1050
1051 if (pt.y >= winSize.height/2) {
1052 return true;
1053 }
1054
1055 return false;
1056}

被这些函数引用 StopPropagationTest().

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

◆ subtitle()

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

重载 TestCase .

在文件 NewEventDispatcherTest.cpp1063 行定义.

1064{
1065 return "Shouldn't crash and only blue block could be clicked";
1066}

◆ title()

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

重载 EventDispatcherTestDemo .

在文件 NewEventDispatcherTest.cpp1058 行定义.

1059{
1060 return "Stop Propagation Test";
1061}

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