Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion HelloWorld/Classes/JsonParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,19 @@ void JsonParser::parseWithText(Page* page, Json::Value &jsonText)
h->videoToPlay = videoToPlayJson.asCString();
}

// actions to run
Json::Value actionsToRunJson = hotspotJson["actionsToRun"];
if (! actionsToRunJson.isNull())
{
for (int j = 0; j < actionsToRunJson.size(); ++j)
{
SpriteAction spriteAction;
spriteAction.spriteTag = actionsToRunJson[j]["spriteTag"].asInt();
spriteAction.actionTag = actionsToRunJson[j]["actionTag"].asInt();
h->actionsToRun.push_back(spriteAction);
}
}

paragraph->hotspots.push_back(h);
}

Expand Down Expand Up @@ -1205,7 +1218,7 @@ void JsonParser::parseWithStoryTouchableNode(Page *page, Json::Value &value)

for (unsigned int j = 0; j < runAction.size(); ++j)
{
StoryTouchableNodeActionsToRun *storyTouchableNodeActionsToRun = new StoryTouchableNodeActionsToRun();
SpriteAction *storyTouchableNodeActionsToRun = new SpriteAction();
storyTouchableNodeActionsToRun->actionTag = runAction[j]["actionTag"].asInt();
storyTouchableNodeActionsToRun->spriteTag = runAction[j]["spriteTag"].asInt();
storyTouchableNode->actionsToRun.push_back(storyTouchableNodeActionsToRun);
Expand Down
15 changes: 8 additions & 7 deletions HelloWorld/Classes/Page.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ typedef struct lineText
int fontSize;
} LineText;

typedef struct spriteAction
{
int spriteTag;
int actionTag;
} SpriteAction;

// hotspot of a paragraph
typedef struct
{
Expand All @@ -48,6 +54,7 @@ typedef struct
std::string soundToPlay;
int touchFlag;
float delayAfterVideoDuringAutoplay;
std::vector<SpriteAction> actionsToRun;

cocos2d::CCParticleSystem *particle; // weak reference
} HotspotInfo;
Expand All @@ -73,19 +80,13 @@ typedef struct sprite
bool visible;
}SpriteInfo;

typedef struct storyTouchableNodeActionsToRun
{
int spriteTag;
int actionTag;
} StoryTouchableNodeActionsToRun;

typedef struct storyTouchableNode
{
HotspotInfo hotspotInfo;
bool delayForText;
bool delayForAnimation;

std::vector<StoryTouchableNodeActionsToRun*> actionsToRun;
std::vector<SpriteAction*> actionsToRun;
} StoryTouchableNode;

typedef struct storySwipeEndedActionsToRun
Expand Down
17 changes: 17 additions & 0 deletions HelloWorld/Classes/PageLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,23 @@ void PageLayer::doHotspotTouched(HotspotInfo *hotspot,bool isParagraphHotspot)
// play
touchSoundId = SimpleAudioEngine::sharedEngine()->playEffect(audeoName.c_str());
}

// run actions
for (int i = 0; i < hotspot->actionsToRun.size(); ++i)
{
CCSprite *sprite = (CCSprite*)getChildByTag(hotspot->actionsToRun[i].spriteTag);

// don't run an action again
if (sprite->getActionByTag(i) != NULL)
{
continue;
}

CCAction *action = (CCAction*)page->getActionByTag(hotspot->actionsToRun[i].actionTag)->copy();
action->setTag(i);

sprite->runAction(action);
}
}

// this call back function will be called by VideoPlayer only with auto play mode
Expand Down
2 changes: 1 addition & 1 deletion cocos2dx/actions/CCActionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void CCActionManager::addAction(CCAction *pAction, CCNode *pTarget, bool paused)

actionAllocWithHashElement(pElement);

CCAssert(! ccArrayContainsObject(pElement->actions, pAction), "");
//CCAssert(! ccArrayContainsObject(pElement->actions, pAction), "");
ccArrayAppendObject(pElement->actions, pAction);

pAction->startWithTarget(pTarget);
Expand Down