#include "BaseLayer.h"BaseLayer::BaseLayer(){}BaseLayer::~BaseLayer(){}bool BaseLayer::init(){ bool bRes = false; do { CC_BREAK_IF(!Layer::init()); bRes = true; } while (0); return bRes;}voID BaseLayer::SetBkGround( const char* bkImage ){ m_SpBk1 = Sprite::create(bkImage); m_SpBk1->setAnchorPoint(Vec2::ZERO); m_SpBk1->setScale(GetWinSize().wIDth / m_SpBk1->getContentSize().wIDth); m_SpBk1->setposition(Vec2::ZERO); m_SpBk2 = Sprite::create(bkImage); m_SpBk2->setFlipX(true); m_SpBk2->setAnchorPoint(Vec2::ZERO); m_SpBk2->setScale(GetWinSize().wIDth / m_SpBk1->getContentSize().wIDth); m_SpBk2->setposition(Vec2(GetWinSize().wIDth,0)); this->addChild(m_SpBk1); this->addChild(m_SpBk2); this->schedule(schedule_selector(BaseLayer::ScrollBkGround),1/60);}Size BaseLayer::GetWinSize(){ return Director::getInstance()->getWinSize();}voID BaseLayer::ScrollBkGround(float dt){ if (m_SpBk1->getpositionX() <= -GetWinSize().wIDth) { m_SpBk1->setposition(GetWinSize().wIDth,0); } if (m_SpBk2->getpositionX() <= -GetWinSize().wIDth) { m_SpBk2->setposition(GetWinSize().wIDth,0); } m_SpBk1->setposition(Vec2(m_SpBk1->getpositionX() - 1,0)); m_SpBk2->setposition(Vec2(m_SpBk2->getpositionX() - 1,0));}
#ifndef __BASELAYER_H__#define __BASELAYER_H__#include "cocos2d.h"USING_NS_CC;class BaseLayer : public Layer{public: BaseLayer(); ~BaseLayer(); virtual bool init() overrIDe; Size GetWinSize(); voID SetBkGround(const char* bkImage); voID ScrollBkGround(float dt);private: Sprite *m_SpBk1; Sprite *m_SpBk2;};#endif总结
以上是内存溢出为你收集整理的cocos2dx 背景无限滚动全部内容,希望文章能够帮你解决cocos2dx 背景无限滚动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)