编辑2:我一直在更新我自己的版本,而且我已经了解到原来的编码器对C不是很好,你可能想在使用它之前查看其中的所有内容,请查看下面的评论
目前可用的CCScrollVIEw for cocos2d-x存在一个主要缺陷:它搞砸了.
具体来说,cpp函数头与.h文件不匹配.
cpp文件引用UIEvent和NSMutableArray,而不是X-Platform.
滚动视图本身必须添加一个数组,这限制了您使用for循环创建菜单项(如果创建菜单项)的能力,因为您不能使用可变的,并且它们不会像iOS所以你不能只使用一个mutable然后说CCArray * array = mutable-> getMutableArray()或类似的.
此外,定义已过时(虽然通过cocos2d-x网站上的转换规则添加CCX_SAFE_DELETE可以修复),以及各种随机模板试图创建甚至不在项目中的NS和UI对象我也没有线索为什么.
基本的想法是,除了使用可变数组之外,这个类太乱了,无法转换为C语言.我不相信作者编译了他的版本,因为标题不匹配.我以为我下载了两个(每个都有2个)cpp和.h文件,并且都有UIEvent而不是CC以及其他问题.
注意:我已经修复了上面的各种内容,并在各个地方将SelectorProtocol更改为CCObject,但它只是变得势不可挡.
也许我应该使用Parallax节点?
这太荒谬了,也许它对Cocos2d来说很棒,但它不适用于c2d-X.无论如何,我会记录和搜索,感谢任何建议!
编辑:这是我现在正在使用的课程.没有完成编辑,但这些将让任何人开始,并编译不仅仅是iPhone
标题:
#ifndef __CCSCRolLLAYER__#define __CCSCRolLLAYER__// CCScrollLayer.h//// copyright 2010 DK101// http://dk101.net/2010/11/30/implementing-page-scrolling-in-cocos2d///// copyright 2010 Giv Parvaneh.// http://www.givp.org/blog/2010/12/30/scrolling-menus-in-cocos2d///// copyright 2011 Stepan Generalov//// copyright 2011 Eli Yukelzon//// Permission is hereby granted,free of charge,to any person obtaining a copy// of this software and associated documentation files (the "Software"),to deal// in the Software without restriction,including without limitation the rights// to use,copy,modify,merge,publish,distribute,sublicense,and/or sell// copIEs of the Software,and to permit persons to whom the Software is// furnished to do so,subject to the following conditions://// The above copyright notice and this permission notice shall be included in// all copIEs or substantial portions of the Software.//// THE SOFTWARE IS PROVIDED "AS IS",WITHOUT WARRANTY OF ANY KIND,EXPRESS OR// IMPLIED,INCLUDING BUT NOT liMITED TO THE WARRANTIES OF MERCHANTABIliTY,// fitness FOR A PARTIculaR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE// AUTHORS OR copYRIGHT HolDERS BE liABLE FOR ANY CLaim,damAGES OR OTHER// liABIliTY,WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE,ARISING FROM,// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEAliNGS IN// THE SOFTWARE.// Original source: https://github.com/cocos2d/cocos2d-iphone-extensions/tree/master/Extensions/CCScrollLayer // Last updated: October 1,2011 #include "cocos2d.h"namespace cocos2d { class CCScrollLayer; class CCScrollLayerDelegate { public: /** Called when scroll layer begins scrolling. * Usefull to cancel CCtouchdispatcher standardDelegates. */ virtual voID scrollLayerScrollingStarted(CCScrollLayer* sender) {} /** Called at the end of movetoPage: * Doesn't get called in selectPage: */ virtual voID scrollLayerScrolledtopageNumber(CCScrollLayer* sender,unsigned int page) {} }; /* It is a very clean and elegant subclass of cclayer that lets you pass-in an array of layers and it will then create a smooth scroller. Complete with the "snapPing" effect. You can create screens with anything that can be added to a cclayer. */ class CCScrollLayer : public cclayer { int currentScreen; //added int totalScreens; float scrollWIDth; float scrollHeight; float startWIDth; float startHeight; int startSwipe; public: //CCScrollLayer(); ~CCScrollLayer(); static CCScrollLayer* nodeWithLayers(CCArray* layers,int wIDthOffset); bool initWithLayers(CCArray* layers,int wIDthOffset); /** Updates all pages positions & adds them as children if needed. * Can be used to update position of pages after screen reshape,or * for update after dynamic page add/remove. */ voID updatePages(); /** Adds new page and reorders pages trying to set given number for newly added page. * If number > pages count - adds new page to the right end of the scroll layer. * If number <= 0 - adds new page to the left end of the scroll layer. * @attention Designated addPage method. */ voID addPage(cclayer* aPage,unsigned int pageNumber); /** Adds new page to the right end of the scroll layer. */ voID addPage(cclayer* aPage); /** Removes page if it's one of scroll layers pages (not children) * Does nothing if page not found. */ voID removePage(cclayer* aPage); /** Removes page with given number. Doesn nothing if there's no page for such number. */ voID removePageWithNumber(unsigned int pageNumber); /* Moves scrollLayer to page with given number & invokes delegate * method scrollLayer:scrolledtopageNumber: at the end of CCMoveto action. * Does nothing if number >= totalScreens or < 0. */ voID movetoPage(unsigned int pageNumber); /* Immedeatly moves scrollLayer to page with given number without running CCMoveto. * Does nothing if number >= totalScreens or < 0. */ voID selectPage(unsigned int pageNumber); CC_SYNTHESIZE(CCScrollLayerDelegate*,m_pDelegate,Delegate); /** Calibration property. Minimum moving touch length that is enough * to cancel menu items and start scrolling a layer. */ CC_SYNTHESIZE(CGfloat,m_fMinimumtouchLengthToSlIDe,MinimumtouchLengthToSlIDe); /** Calibration property. Minimum moving touch length that is enough to change * the page,without snapPing back to the prevIoUs selected page. */ CC_SYNTHESIZE(CGfloat,m_fMinimumtouchLengthtochangePage,MinimumtouchLengthtochangePage); /** If YES - when starting scrolling CCScrollLayer will claim touches,that are * already claimed by others targetedtouchDelegates by calling CCtouchdispatcher#touchesCancelled * Usefull to have ability to scroll with touch above menus in pages. * If NO - scrolling will start,but no touches will be cancelled. * Default is YES. */ CC_SYNTHESIZE(bool,m_bStealtouches,Stealtouches); /** Whenever show or not white/grey dots under the scroll layer. * If yes - dots will be rendered in parents transform (rendered after scroller visit). */ CC_SYNTHESIZE(bool,m_bShowPagesIndicator,ShowPagesIndicator); /** position of dots center in parent coordinates. * (Default value is screenWIDth/2,screenHeight/4) */ CC_SYNTHESIZE_PASS_BY_REF(CCPoint,m_tPagesIndicatorposition,PagesIndicatorposition); /** Total pages available in scrollLayer. */ unsigned int getTotalScreens() const; /** Current page number,that is shown. Belongs to the [0,totalScreen] interval. */ CC_SYNTHESIZE_Readonly(unsigned int,m_uCurrentScreen,CurrentScreen); /** Offset,that can be used to let user see next/prevIoUs page. */ CC_SYNTHESIZE(CGfloat,m_fPagesWIDthOffset,PagesWIDthOffset); /** Offset that can be used to let user see empty space over first or last page. */ CC_SYNTHESIZE(CGfloat,m_fmarginOffset,marginOffset); /** Array of pages cclayer's */ CC_SYNTHESIZE_Readonly(CCArray*,m_pLayers,Pages); protected: // The x coord of initial point the user starts their swipe. CGfloat m_fStartSwipe; // Internal state of scrollLayer (scrolling or IDle). int m_iState; bool m_bStealingtouchInProgress; // Holds the touch that started the scroll CCtouch* m_pScrolltouch; //voID visit(); //voID movetoPageEnded(); unsigned int pageNumberForposition(const CCPoint& position); CCPoint positionForPageWithNumber(unsigned int pageNumber); voID claimtouch(CCtouch* ptouch); voID cancelAndStoletouch(CCtouch* ptouch,CCEvent* pEvent); //voID registerWithtouchdispatcher(); bool cctouchBegan(CCtouch* ptouch,CCEvent* pEvent); voID cctouchmoved(CCtouch* ptouch,CCEvent* pEvent); voID cctouchended(CCtouch* ptouch,CCEvent* pEvent); //voID cctouchCancelled(CCtouch* ptouch,CCEvent* pEvent); };} //end namespace#endif
CPP
// CCScrollLayer.cpp// Museum//// Created by GParvaneh on 29/12/2010.// copyright 2010. All rights reserved.// Ported to C++ by lior Tamam on 03/04/2011#include "CCScrollLayer.h"using namespace cocos2d;CCScrollLayer* CCScrollLayer::nodeWithLayers(CCArray* layers,int wIDthOffset){ CCScrollLayer *pRet = new CCScrollLayer(); if (pRet && pRet->initWithLayers(layers,wIDthOffset)) { pRet->autorelease(); return pRet; } CCX_SAFE_DELETE(pRet); return NulL;}bool CCScrollLayer::initWithLayers(CCArray* layers,int wIDthOffset){ if (cclayer::init()) { // Make sure the layer accepts touches CCtouchdispatcher::shareddispatcher()->addTargetedDelegate(this,true); // Set up the starting variables //if(!wIDthOffset) { // wIDthOffset = 0; } currentScreen = 1; // offset added to show prevIEw of next/prevIoUs screens scrollWIDth = (int)CCDirector::sharedDirector()->getWinSize().wIDth - wIDthOffset; scrollHeight = (int)CCDirector::sharedDirector()->getWinSize().height; startWIDth = scrollWIDth; startHeight = scrollHeight; // Loop through the array and add the screens unsigned int i; for (i=0; i<layers->count(); i++) { cclayer* l = (cclayer*)layers->objectAtIndex(i); //l->setAnchorPoint(ccp(0,0)); //l->setposition(ccp((i*scrollWIDth),0)); addChild(l); } // Setup a count of the available screens totalScreens = layers->count(); return true; } else { return false; } }voID CCScrollLayer::setMaximumScrollHeight(float maxHeight){ //Make the offset match expected pixels (include the current screen if at ccp(0,0) maxHeight -= CCDirector::sharedDirector()->getWinSize().height; maximumScrollHeight = maxHeight;} CCScrollLayer::~CCScrollLayer(){ CCtouchdispatcher::shareddispatcher()->removeDelegate(this); cclayer::onExit();}bool CCScrollLayer::cctouchBegan(CCtouch *touch,CCEvent *withEvent){// // CCPoint touchPoint = touch->locationInVIEw();// touchPoint = CCDirector::sharedDirector()->convertToGL(touchPoint);// // startSwipe = (int)touchPoint.y; return true;}voID CCScrollLayer::cctouchmoved(CCtouch *touch,CCEvent *withEvent){ CCPoint touchPoint = touch->locationInVIEw(); CCPoint prevPoint = touch->prevIoUsLocationInVIEw(); touchPoint = CCDirector::sharedDirector()->convertToGL(touchPoint); prevPoint = CCDirector::sharedDirector()->convertToGL(prevPoint); CCPoint difference = ccp( touchPoint.x - prevPoint.x,touchPoint.y - prevPoint.y); CCPoint currentPos = this->getposition(); currentPos = ccp( currentPos.x,currentPos.y+difference.y); if (currentPos.y > maximumScrollHeight) { currentPos.y = maximumScrollHeight; //this->setpositionY(maximumScrollHeight); } else if (currentPos.y < 0) { currentPos.y = 0; // this->setpositionY(0); } this->setposition(currentPos);}/*voID CCScrollLayer::cctouchended(CCtouch *touch,CCEvent *withEvent){ //CCPoint touchPoint = touch->locationInVIEw(); //touchPoint = CCDirector::sharedDirector()->convertToGL(touchPoint); int newX = (int)touchPoint.x; if ( (newX - startSwipe) < -scrollWIDth / 3 && (currentScreen+1) <= totalScreens ) { // this->movetoNextPage(); } else if ( (newX - startSwipe) > scrollWIDth / 3 && (currentScreen-1) > 0 ) { // this->movetoPrevIoUsPage(); } else { // this->movetoPage(currentScreen); } }*/对于通过搜索引擎找到此内容的任何人来说,恢复旧线程以添加新信息:
CCScrollView
现在是GUI扩展的一部分,并且似乎运行得相当好.不再需要上面提到的实现. 总结 以上是内存溢出为你收集整理的跨平台 – CCScrollView for cocos2d-x有效吗?全部内容,希望文章能够帮你解决跨平台 – CCScrollView for cocos2d-x有效吗?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)