no message

This commit is contained in:
chengstory 2013-06-04 17:54:05 +08:00
parent cfb424a6c9
commit a5f8e2c27e
2 changed files with 50 additions and 5 deletions

View File

@ -63,14 +63,17 @@ static const std::string testsName[TEST_MAX_COUNT] =
// ExtensionsMainLayer // ExtensionsMainLayer
// //
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
static CCPoint s_tCurPos = CCPointZero;
void ExtensionsMainLayer::onEnter() void ExtensionsMainLayer::onEnter()
{ {
CCLayer::onEnter(); CCLayer::onEnter();
CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSize s = CCDirector::sharedDirector()->getWinSize();
CCMenu* pMenu = CCMenu::create(); m_pItemMenu = CCMenu::create();
pMenu->setPosition( CCPointZero ); m_pItemMenu->setPosition( CCPointZero );
CCMenuItemFont::setFontName("Arial"); CCMenuItemFont::setFontName("Arial");
CCMenuItemFont::setFontSize(24); CCMenuItemFont::setFontSize(24);
for (int i = 0; i < TEST_MAX_COUNT; ++i) for (int i = 0; i < TEST_MAX_COUNT; ++i)
@ -78,10 +81,10 @@ void ExtensionsMainLayer::onEnter()
CCMenuItemFont* pItem = CCMenuItemFont::create(testsName[i].c_str(), this, CCMenuItemFont* pItem = CCMenuItemFont::create(testsName[i].c_str(), this,
menu_selector(ExtensionsMainLayer::menuCallback)); menu_selector(ExtensionsMainLayer::menuCallback));
pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE)); pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE));
pMenu->addChild(pItem, kItemTagBasic + i); m_pItemMenu->addChild(pItem, kItemTagBasic + i);
} }
setTouchEnabled(true);
addChild(pMenu); addChild(m_pItemMenu);
} }
void ExtensionsMainLayer::menuCallback(CCObject* pSender) void ExtensionsMainLayer::menuCallback(CCObject* pSender)
@ -150,6 +153,43 @@ void ExtensionsMainLayer::menuCallback(CCObject* pSender)
} }
} }
void ExtensionsMainLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
CCSetIterator it = pTouches->begin();
CCTouch* touch = (CCTouch*)(*it);
m_tBeginPos = touch->getLocation();
}
void ExtensionsMainLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
CCSetIterator it = pTouches->begin();
CCTouch* touch = (CCTouch*)(*it);
CCPoint touchLocation = touch->getLocation();
float nMoveY = touchLocation.y - m_tBeginPos.y;
CCPoint curPos = m_pItemMenu->getPosition();
CCPoint nextPos = ccp(curPos.x, curPos.y + nMoveY);
if (nextPos.y < 0.0f)
{
m_pItemMenu->setPosition(CCPointZero);
return;
}
if (nextPos.y > ((TEST_MAX_COUNT + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height))
{
m_pItemMenu->setPosition(ccp(0, ((TEST_MAX_COUNT + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
return;
}
m_pItemMenu->setPosition(nextPos);
m_tBeginPos = touchLocation;
s_tCurPos = nextPos;
}
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// //
// ExtensionsTestScene // ExtensionsTestScene

View File

@ -8,6 +8,11 @@ class ExtensionsMainLayer : public CCLayer
public: public:
virtual void onEnter(); virtual void onEnter();
void menuCallback(CCObject* pSender); void menuCallback(CCObject* pSender);
virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);
private:
CCPoint m_tBeginPos;
CCMenu* m_pItemMenu;
}; };
class ExtensionsTestScene : public TestScene class ExtensionsTestScene : public TestScene