add ParallaxTest code
This commit is contained in:
natural-law 2010-09-01 06:57:55 +00:00
parent c6789ef16d
commit 4b529493fc
18 changed files with 393 additions and 14 deletions

View File

@ -63,10 +63,11 @@ THE SOFTWARE.
#include "CCGridAction.h"
#include "CCBitmapFontAtlas.h"
#include "CCParallaxNode.h"
// #include "CCTMXTiledMap.h"
// #include "CCTMXLayer.h"
// #include "CCTMXObjectGroup.h"
// #include "CCTMXXMLParser.h"
#include "CCTileMapAtlas.h"
#include "CCTMXTiledMap.h"
#include "CCTMXLayer.h"
#include "CCTMXObjectGroup.h"
#include "CCTMXXMLParser.h"
#include "CCRenderTexture.h"
#include "CCMotionStreak.h"
#include "CCPageTurn3DAction.h"

View File

@ -525,6 +525,18 @@
>
</File>
</Filter>
<Filter
Name="ParallaxTest"
>
<File
RelativePath=".\tests\ParallaxTest\ParallaxTest.cpp"
>
</File>
<File
RelativePath=".\tests\ParallaxTest\ParallaxTest.h"
>
</File>
</Filter>
</Filter>
<File
RelativePath=".\test_uphoneUnicodeScript.h"

View File

@ -2,7 +2,7 @@
#define _ActionsTest_H_
#include "../testBasic.h"
#include "cocos2d.h"
////----#include "cocos2d.h"
using namespace cocos2d;

View File

@ -1,7 +1,7 @@
#ifndef _COCOSNODE_TEST_H_
#define _COCOSNODE_TEST_H_
#include "cocos2d.h"
////----#include "cocos2d.h"
#include "../testBasic.h"
class TestCocosNodeDemo : public CCLayer

View File

@ -1,7 +1,7 @@
#ifndef _DRAW_PRIMITIVES_TEST_H_
#define _DRAW_PRIMITIVES_TEST_H_
#include "cocos2d.h"
////----#include "cocos2d.h"
#include "../testBasic.h"
class DrawPrimitivesTest : public CCLayer

View File

@ -1,7 +1,7 @@
#ifndef _EASE_ACTIONS_TEST_H_
#define _EASE_ACTIONS_TEST_H_
#include "cocos2d.h"
////----#include "cocos2d.h"
#include "../testBasic.h"
using namespace cocos2d;

View File

@ -1,7 +1,7 @@
#ifndef _LAYER_TEST_H_
#define _LAYER_TEST_H_
#include "cocos2d.h"
////----#include "cocos2d.h"
#include "../testBasic.h"
class LayerTest : public CCLayer

View File

@ -1,7 +1,7 @@
#ifndef _MENU_TEST_H_
#define _MENU_TEST_H_
#include "cocos2d.h"
////----#include "cocos2d.h"
#include "../testBasic.h"
class MenuLayer1 : public CCLayer

View File

@ -1,7 +1,7 @@
#ifndef _MOTION_STREAK_TEST_H_
#define _MOTION_STREAK_TEST_H_
#include "cocos2d.h"
////----#include "cocos2d.h"
#include "../testBasic.h"
//using namespace cocos2d;

View File

@ -0,0 +1,288 @@
#include "ParallaxTest.h"
#include "../testResource.h"
enum
{
kTagNode,
kTagGrossini,
};
//------------------------------------------------------------------
//
// Parallax1
//
//------------------------------------------------------------------
Parallax1::Parallax1()
{
// Top Layer, a simple image
CCSprite* cocosImage = CCSprite::spriteWithFile(s_Power);
// scale the image (optional)
cocosImage->setScale( 2.5f );
// change the transform anchor point to 0,0 (optional)
cocosImage->setAnchorPoint( ccp(0,0) );
// Middle layer: a Tile map atlas
CCTileMapAtlas *tilemap = CCTileMapAtlas::tileMapAtlasWithTileFile(s_TilesPng, s_LevelMapTga, 16, 16);
tilemap->releaseMap();
// change the transform anchor to 0,0 (optional)
tilemap->setAnchorPoint( ccp(0, 0) );
// Aliased images
// [tilemap.texture setAliasTexParameters];
// background layer: another image
CCSprite* background = CCSprite::spriteWithFile(s_back);
// scale the image (optional)
background->setScale( 1.5f );
// change the transform anchor point (optional)
background->setAnchorPoint( ccp(0,0) );
// create a void node, a parent node
CCParallaxNode* voidNode = CCParallaxNode::node();
// NOW add the 3 layers to the 'void' node
// background image is moved at a ratio of 0.4x, 0.5y
voidNode->addChild(background, -1, ccp(0.4f,0.5f), CGPointZero);
// tiles are moved at a ratio of 2.2x, 1.0y
voidNode->addChild(tilemap, 1, ccp(2.2f,1.0f), ccp(0,-200) );
// top image is moved at a ratio of 3.0x, 2.5y
voidNode->addChild(cocosImage, 2, ccp(3.0f,2.5f), ccp(200,800) );
// now create some actions that will move the 'void' node
// and the children of the 'void' node will move at different
// speed, thus, simulation the 3D environment
CCIntervalAction* goUp = CCMoveBy::actionWithDuration(4, ccp(0,-500) );
CCIntervalAction* goDown = goUp->reverse();
CCIntervalAction* go = CCMoveBy::actionWithDuration(8, ccp(-1000,0) );
CCIntervalAction* goBack = go->reverse();
CCFiniteTimeAction* seq = CCSequence::actions(goUp, go, goDown, goBack, NULL);
voidNode->runAction( (CCRepeatForever::actionWithAction((CCIntervalAction*) seq) ));
addChild( voidNode );
}
std::string Parallax1::title()
{
return "MotionStreak test (tap screen)";
}
//------------------------------------------------------------------
//
// Parallax2
//
//------------------------------------------------------------------
Parallax2::Parallax2()
{
setIsTouchEnabled( true );
// Top Layer, a simple image
CCSprite* cocosImage = CCSprite::spriteWithFile(s_Power);
// scale the image (optional)
cocosImage->setScale( 2.5f );
// change the transform anchor point to 0,0 (optional)
cocosImage->setAnchorPoint( ccp(0,0) );
// Middle layer: a Tile map atlas
CCTileMapAtlas* tilemap = CCTileMapAtlas::tileMapAtlasWithTileFile(s_TilesPng, s_LevelMapTga, 16, 16);
tilemap->releaseMap();
// change the transform anchor to 0,0 (optional)
tilemap->setAnchorPoint( ccp(0, 0) );
// Aliased images
// [tilemap.texture setAliasTexParameters];
// background layer: another image
CCSprite* background = CCSprite::spriteWithFile(s_back);
// scale the image (optional)
background->setScale( 1.5f );
// change the transform anchor point (optional)
background->setAnchorPoint( ccp(0,0) );
// create a void node, a parent node
CCParallaxNode* voidNode = CCParallaxNode::node();
// NOW add the 3 layers to the 'void' node
// background image is moved at a ratio of 0.4x, 0.5y
voidNode->addChild(background, -1, ccp(0.4f,0.5f), CGPointZero);
// tiles are moved at a ratio of 1.0, 1.0y
voidNode->addChild(tilemap, 1, ccp(1.0f,1.0f), ccp(0,-200) );
// top image is moved at a ratio of 3.0x, 2.5y
voidNode->addChild( cocosImage, 2, ccp(3.0f,2.5f), ccp(200,1000) );
addChild(voidNode, 0, kTagNode);
}
void Parallax2::registerWithTouchDispatcher()
{
CCTouchDispatcher::getSharedDispatcher()->addTargetedDelegate(this, 0, true);
}
bool Parallax2::ccTouchBegan(CCTouch* touch, UIEvent* event)
{
return true;
}
void Parallax2::ccTouchEnded(CCTouch* touch, UIEvent* event)
{
}
void Parallax2::ccTouchCancelled(CCTouch* touch, UIEvent* event)
{
}
void Parallax2::ccTouchMoved(CCTouch* touch, UIEvent* event)
{
CGPoint touchLocation = touch->locationInView( touch->view() );
CGPoint prevLocation = touch->previousLocationInView( touch->view() );
touchLocation = CCDirector::getSharedDirector()->convertToGL( touchLocation );
prevLocation = CCDirector::getSharedDirector()->convertToGL( prevLocation );
CGPoint diff = ccpSub(touchLocation,prevLocation);
CCNode* node = getChildByTag(kTagNode);
CGPoint currentPos = node->getPosition();
node->setPosition( ccpAdd(currentPos, diff) );
}
std::string Parallax2::title()
{
return "Parallax: drag screen";
}
//------------------------------------------------------------------
//
// ParallaxDemo
//
//------------------------------------------------------------------
static int sceneIdx = -1;
#define MAX_LAYER 2
CCLayer* createParallaxTestLayer(int nIndex)
{
switch(nIndex)
{
case 0: return new Parallax1();
case 1: return new Parallax2();
}
return NULL;
}
CCLayer* nextParallaxAction()
{
sceneIdx++;
sceneIdx = sceneIdx % MAX_LAYER;
CCLayer* pLayer = createParallaxTestLayer(sceneIdx);
pLayer->autorelease();
return pLayer;
}
CCLayer* backParallaxAction()
{
sceneIdx--;
int total = MAX_LAYER;
if( sceneIdx < 0 )
sceneIdx += total;
CCLayer* pLayer = createParallaxTestLayer(sceneIdx);
pLayer->autorelease();
return pLayer;
}
CCLayer* restartParallaxAction()
{
CCLayer* pLayer = createParallaxTestLayer(sceneIdx);
pLayer->autorelease();
return pLayer;
}
ParallaxDemo::ParallaxDemo(void)
{
}
ParallaxDemo::~ParallaxDemo(void)
{
}
std::string ParallaxDemo::title()
{
return "No title";
}
void ParallaxDemo::onEnter()
{
__super::onEnter();
CGSize s = CCDirector::getSharedDirector()->getWinSize();
CCLabel* label = CCLabel::labelWithString(title().c_str(), "Arial", 28);
addChild(label, 1);
label->setPosition( ccp(s.width/2, s.height-50) );
CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(ParallaxDemo::backCallback) );
CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(ParallaxDemo::restartCallback) );
CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(ParallaxDemo::nextCallback) );
CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);
menu->setPosition( CGPointZero );
item1->setPosition( ccp( s.width/2 - 100,30) );
item2->setPosition( ccp( s.width/2, 30) );
item3->setPosition( ccp( s.width/2 + 100,30) );
addChild(menu, 1);
}
void ParallaxDemo::restartCallback(NSObject* pSender)
{
CCScene* s = new ParallaxTestScene();
s->addChild(restartParallaxAction());
CCDirector::getSharedDirector()->replaceScene(s);
}
void ParallaxDemo::nextCallback(NSObject* pSender)
{
CCScene* s = new ParallaxTestScene();
s->addChild( nextParallaxAction() );
CCDirector::getSharedDirector()->replaceScene(s);
}
void ParallaxDemo::backCallback(NSObject* pSender)
{
CCScene* s = new ParallaxTestScene();
s->addChild( backParallaxAction() );
CCDirector::getSharedDirector()->replaceScene(s);
}
void ParallaxTestScene::runThisTest()
{
CCLayer* pLayer = nextParallaxAction();
addChild(pLayer);
CCDirector::getSharedDirector()->replaceScene(this);
}

View File

@ -0,0 +1,60 @@
#ifndef _PARALLAX_TEST_H_
#define _PARALLAX_TEST_H_
#include "../testBasic.h"
class ParallaxDemo : public CCLayer
{
protected:
CCTextureAtlas* m_atlas;
public:
ParallaxDemo(void);
~ParallaxDemo(void);
virtual std::string title();
virtual void onEnter();
void restartCallback(NSObject* pSender);
void nextCallback(NSObject* pSender);
void backCallback(NSObject* pSender);
};
class Parallax1 : public ParallaxDemo
{
protected:
CCNode* m_root;
CCNode* m_target;
CCMotionStreak* m_streak;
public:
Parallax1();
virtual std::string title();
};
class Parallax2 : public ParallaxDemo
{
protected:
CCNode* m_root;
CCNode* m_target;
CCMotionStreak* m_streak;
public:
Parallax2();
virtual void registerWithTouchDispatcher();
virtual bool ccTouchBegan(CCTouch* touch, UIEvent* event);
virtual void ccTouchEnded(CCTouch* touch, UIEvent* event);
virtual void ccTouchCancelled(CCTouch* touch, UIEvent* event);
virtual void ccTouchMoved(CCTouch* touch, UIEvent* event);
virtual std::string title();
};
class ParallaxTestScene : public TestScene
{
public:
virtual void runThisTest();
};
#endif

View File

@ -2,7 +2,7 @@
#define _PARTICLE_TEST_H_
#include "../testBasic.h"
#include "cocos2d.h"
////----#include "cocos2d.h"
// #include "touch_dispatcher/CCTouch.h"
// #include "CCParticleExample.h"

View File

@ -1,7 +1,7 @@
#ifndef _SCENE_TEST_H_
#define _SCENE_TEST_H_
#include "cocos2d.h"
////----#include "cocos2d.h"
#include "../testBasic.h"
class SceneTestLayer1 : public CCLayer

View File

@ -1,4 +1,7 @@
#include "cocos2d.h"
#ifndef _TOUCHES_TEST__H_
#define _TOUCHES_TEST__H_
////----#include "cocos2d.h"
#include "../testBasic.h"
using namespace cocos2d;
@ -25,3 +28,5 @@ public:
void resetAndScoreBallForPlayer(int player);
void doStep(ccTime delta);
};
#endif

View File

@ -47,6 +47,8 @@ static TestScene* CreateTestScene(int nIdx)
pScene = new LayerTestScene(); break;
case TEST_SCENE:
pScene = new SceneTestScene(); break;
case TEST_PARALLAX:
pScene = new ParallaxTestScene(); break;
default:
break;
}

View File

@ -11,6 +11,7 @@ static const char s_pPathR2[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_test
static const char s_pPathF1[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_tests/Images/f1.png";
static const char s_pPathF2[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_tests/Images/f2.png";
static const char s_pPathBlock[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_tests/Images/blocks.png";
static const char s_back[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_tests/Images/background.png";
static const char s_back1[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_tests/Images/background1.png";
static const char s_back2[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_tests/Images/background2.png";
static const char s_back3[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_tests/Images/background3.png";
@ -31,5 +32,10 @@ static const char s_pPathClose[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_test
static const char s_MenuItem[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_tests/Images/menuitemsprite.png";
static const char s_SendScore[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_tests/Images/SendScoreButton.png";
static const char s_PressSendScore[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_tests/Images/SendScoreButtonPressed.png";
static const char s_Power[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_tests/Images/powered.png";
// tilemaps resource
static const char s_TilesPng[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_tests/TileMaps/tiles.png";
static const char s_LevelMapTga[] = "/NEWPLUS/TDA_DATA/Data/cocos2d_tests/TileMaps/levelmap.tga";
#endif

View File

@ -17,6 +17,7 @@
#include "ActionManagerTest/ActionManagerTest.h"
#include "LayerTest/LayerTest.h"
#include "SceneTest/SceneTest.h"
#include "ParallaxTest/ParallaxTest.h"
enum
{
@ -36,6 +37,7 @@ enum
TEST_ACTION_MANAGER,
TEST_LAYER,
TEST_SCENE,
TEST_PARALLAX,
TESTS_COUNT,
};
@ -56,6 +58,7 @@ const std::string g_aTestNames[TESTS_COUNT] = {
"ActionManagerTest",
"LayerTest",
"SceneTest",
"ParallaxTest",
};
#endif

View File

@ -1,5 +1,7 @@
mkdir D:\Work7\NEWPLUS\TDA_DATA\Data\cocos2d_tests\Images
mkdir D:\Work7\NEWPLUS\TDA_DATA\Data\cocos2d_tests\TileMaps
copy .\Res\Images\*.* D:\Work7\NEWPLUS\TDA_DATA\Data\cocos2d_tests\Images
copy .\Res\TileMaps\*.* D:\Work7\NEWPLUS\TDA_DATA\Data\cocos2d_tests\TileMaps
copy .\Res\Images\fire.png D:\Work7\NEWPLUS\TDA_DATA\UserData
copy .\Res\Images\fps_images.png D:\Work7\NEWPLUS\TDA_DATA\UserData
copy .\Res\Images\HelloWorld.png D:\Work7\NEWPLUS\TDA_DATA\UserData