简体   繁体   English

在cocos2dx中的“页面”(CCLayer)之间移动

[英]Moving between “pages” ( CCLayer ) in cocos2dx

I have 2 MyGameScreen objects that extends cocos2d::CCLayer. 我有2个MycosScreen对象,它们扩展了cocos2d :: CCLayer。 I am capturing the ccTouchesMove of the first screen so that I can create the moving effect exactly like sliding between pages of iOS application screen. 我正在捕获第一个屏幕的ccTouchesMove,以便可以像在iOS应用程序屏幕的页面之间滑动一样创建移动效果。

My class is like so: 我的课是这样的:

class MyGameScreen: public cocos2d::CCLayer {
    cocos2d::CCLayer* m_pNextScreen;
}

bool MyGameScreen::init() {
    m_pNextScreen = MyOtherScreen::create();
}

void MyGameScreen::ccTouchesMoved(CCSet *touches, CCEvent *event){
    // it crashes here... on the setPosition... m_pNextScreen is valid pointer though I am not sure that MyOtherScreen::create() is all I need to do...
    m_pNextScreen->setPosition( CCPointMake( (fMoveTo - (2*fScreenHalfWidth)), 0.0f ) );
}

EDIT: adding clear question 编辑:添加明确的问题

It crashed when I try to setPosition on m_pNextScreen... 当我尝试在m_pNextScreen上设置setPosition时,它崩溃了...

I have no idea why it crashed as m_pNextScreen is a valid pointer and is properly initialized. 我不知道为什么它会崩溃,因为m_pNextScreen是有效的指针并已正确初始化。 Could anybody explain why? 有人可以解释为什么吗?

EDIT: adding progress report 编辑:添加进度报告

I remodelled the whole system and make a class CContainerLayer : public cocos2d::CCLayer that contains both MyGameScreen and MyOtherScreen side by side. 我对整个系统进行了重新class CContainerLayer : public cocos2d::CCLayer ,并制作了一个class CContainerLayer : public cocos2d::CCLayer ,它同时包含MyGameScreenMyOtherScreen However, this looked like not an efficient approach, as when it grows I may need to have more than 2 pages scrollable side by side, I'd prefer to load the next page only when it is needed rather than the entire CContainerLayer that contains all the upcoming pages whether the user will scroll there or not... Do you have any better idea or github open source sample that does this? 但是,这似乎不是一种有效的方法,因为当它增长时,我可能需要并排滚动两个页面以上,我希望仅在需要时才加载下一页,而不是包含所有内容的整个CContainerLayer 。用户是否会滚动到即将到来的页面...您是否有更好的主意或github开源示例呢?

Thank you very much for your input! 非常感谢您的投入!

Use paging enable scrollview.download files from following link and place in your cocos2d/extenision/gui/ after that you have to set property of scrollview to enablepaging true with paging view size. 从以下链接使用分页启用scrollview.download文件,并将其放置在cocos2d / extenision / gui /中,之后,您必须设置scrollview的属性以启用分页视图大小的truepaging。

https://github.com/shauket/paging-scrollview https://github.com/shauket/paging-scrollview

For Scene Transitions you can do this: 对于场景过渡,您可以执行以下操作:

void MyGameScreen::ccTouchesMoved(CCSet *touches, CCEvent *event) void MyGameScreen :: ccTouchesMoved(CCSet * touches,CCEvent * event)

{ {

CCScene* MyOtherScene = CCTransitionFadeUp::create(0.2f, MyOtherScreen::scene()); CCScene * MyOtherScene = CCTransitionFadeUp :: create(0.2f,MyOtherScreen :: scene());

CCDirector::sharedDirector()->replaceScene(MyOtherScene); CCDirector :: sharedDirector()-> replaceScene(MyOtherScene);

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM