fixed #486, setDepthTest(true) in TileMapTest, while setDepthTest(false) in TransitionsTest. TransitionFlip will not flickers any more :)

This commit is contained in:
Walzer 2011-05-12 10:52:10 +08:00
parent 78d49e9806
commit 10d94fb170
2 changed files with 178 additions and 170 deletions

View File

@ -28,11 +28,11 @@ TileMapTest::TileMapTest()
map->setAnchorPoint( ccp(0, 0.5f) ); map->setAnchorPoint( ccp(0, 0.5f) );
CCScaleBy *scale = CCScaleBy::actionWithDuration(4, 0.8f); CCScaleBy *scale = CCScaleBy::actionWithDuration(4, 0.8f);
CCActionInterval *scaleBack = scale->reverse(); CCActionInterval *scaleBack = scale->reverse();
CCFiniteTimeAction* seq = CCSequence::actions(scale, scaleBack, NULL); CCFiniteTimeAction* seq = CCSequence::actions(scale, scaleBack, NULL);
map->runAction(CCRepeatForever::actionWithAction((CCActionInterval *)seq)); map->runAction(CCRepeatForever::actionWithAction((CCActionInterval *)seq));
} }
@ -1114,62 +1114,62 @@ std::string TMXOrthoMoveLayer::subtitle()
// TMXBug987 // TMXBug987
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
TMXBug987::TMXBug987() TMXBug987::TMXBug987()
{ {
CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/orthogonal-test6.tmx"); CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/orthogonal-test6.tmx");
addChild(map, 0, kTagTileMap); addChild(map, 0, kTagTileMap);
CCSize s1 = map->getContentSize(); CCSize s1 = map->getContentSize();
CCLOG("ContentSize: %f, %f", s1.width,s1.height); CCLOG("ContentSize: %f, %f", s1.width,s1.height);
CCArray* childs = map->getChildren(); CCArray* childs = map->getChildren();
CCTMXLayer* pNode; CCTMXLayer* pNode;
CCObject* pObject = NULL; CCObject* pObject = NULL;
CCARRAY_FOREACH(childs, pObject) CCARRAY_FOREACH(childs, pObject)
{ {
pNode = (CCTMXLayer*) pObject; pNode = (CCTMXLayer*) pObject;
CC_BREAK_IF(!pNode); CC_BREAK_IF(!pNode);
pNode->getTexture()->setAntiAliasTexParameters(); pNode->getTexture()->setAntiAliasTexParameters();
} }
map->setAnchorPoint(ccp(0, 0)); map->setAnchorPoint(ccp(0, 0));
CCTMXLayer *layer = map->layerNamed("Tile Layer 1"); CCTMXLayer *layer = map->layerNamed("Tile Layer 1");
layer->setTileGID(3, ccp(2,2)); layer->setTileGID(3, ccp(2,2));
} }
std::string TMXBug987::title() std::string TMXBug987::title()
{ {
return "TMX Bug 987"; return "TMX Bug 987";
} }
std::string TMXBug987::subtitle() std::string TMXBug987::subtitle()
{ {
return "You should see an square"; return "You should see an square";
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
// TMXBug787 // TMXBug787
// //
//------------------------------------------------------------------ //------------------------------------------------------------------
TMXBug787::TMXBug787() TMXBug787::TMXBug787()
{ {
CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/iso-test-bug787.tmx"); CCTMXTiledMap *map = CCTMXTiledMap::tiledMapWithTMXFile("TileMaps/iso-test-bug787.tmx");
addChild(map, 0, kTagTileMap); addChild(map, 0, kTagTileMap);
map->setScale(0.25f); map->setScale(0.25f);
} }
std::string TMXBug787::title() std::string TMXBug787::title()
{ {
return "TMX Bug 787"; return "TMX Bug 787";
} }
std::string TMXBug787::subtitle() std::string TMXBug787::subtitle()
{ {
return "You should see a map"; return "You should see a map";
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
// //
// TileDemo // TileDemo
@ -1376,5 +1376,10 @@ void TileMapTestScene::runThisTest()
CCLayer* pLayer = nextTileMapAction(); CCLayer* pLayer = nextTileMapAction();
addChild(pLayer); addChild(pLayer);
// fix bug #486, #419.
// "test" is the default value in CCDirector::setGLDefaultValues()
// but TransitionTest may setDepthTest(false), we should revert it here
CCDirector::sharedDirector()->setDepthTest(true);
CCDirector::sharedDirector()->replaceScene(this); CCDirector::sharedDirector()->replaceScene(this);
} }

View File

@ -1,8 +1,8 @@
#include "TransitionsTest.h" #include "TransitionsTest.h"
#include "../testResource.h" #include "../testResource.h"
#define TRANSITION_DURATION (1.2f) #define TRANSITION_DURATION (1.2f)
class FadeWhiteTransition : public CCTransitionFade class FadeWhiteTransition : public CCTransitionFade
{ {
public: public:
@ -137,10 +137,10 @@ public:
{ {
return CCTransitionPageTurn::transitionWithDuration(t, s, true); return CCTransitionPageTurn::transitionWithDuration(t, s, true);
} }
}; };
#define MAX_LAYER 37 #define MAX_LAYER 37
static std::string transitions[MAX_LAYER] = { static std::string transitions[MAX_LAYER] = {
"JumpZoomTransition", "JumpZoomTransition",
"FadeTransition", "FadeTransition",
@ -167,22 +167,22 @@ static std::string transitions[MAX_LAYER] = {
"SlideInRTransition", "SlideInRTransition",
"SlideInTTransition", "SlideInTTransition",
"SlideInBTransition", "SlideInBTransition",
"CCTransitionCrossFade", "CCTransitionCrossFade",
"CCTransitionRadialCCW", "CCTransitionRadialCCW",
"CCTransitionRadialCW", "CCTransitionRadialCW",
"PageTransitionForward", "PageTransitionForward",
"PageTransitionBackward", "PageTransitionBackward",
"FadeTRTransition", "FadeTRTransition",
"FadeBLTransition", "FadeBLTransition",
"FadeUpTransition", "FadeUpTransition",
"FadeDownTransition", "FadeDownTransition",
"TurnOffTilesTransition", "TurnOffTilesTransition",
"SplitRowsTransition", "SplitRowsTransition",
"SplitColsTransition", "SplitColsTransition",
}; };
static int s_nSceneIdx = 0; static int s_nSceneIdx = 0;
CCTransitionScene* createTransition(int nIndex, ccTime t, CCScene* s) CCTransitionScene* createTransition(int nIndex, ccTime t, CCScene* s)
{ {
switch(nIndex) switch(nIndex)
@ -196,12 +196,12 @@ CCTransitionScene* createTransition(int nIndex, ccTime t, CCScene* s)
case 6: return FlipYDownOver::transitionWithDuration(t, s); case 6: return FlipYDownOver::transitionWithDuration(t, s);
case 7: return FlipAngularLeftOver::transitionWithDuration(t, s); case 7: return FlipAngularLeftOver::transitionWithDuration(t, s);
case 8: return FlipAngularRightOver::transitionWithDuration(t, s); case 8: return FlipAngularRightOver::transitionWithDuration(t, s);
case 9: return ZoomFlipXLeftOver::transitionWithDuration(t, s); case 9: return ZoomFlipXLeftOver::transitionWithDuration(t, s);
case 10: return ZoomFlipXRightOver::transitionWithDuration(t, s); case 10: return ZoomFlipXRightOver::transitionWithDuration(t, s);
case 11: return ZoomFlipYUpOver::transitionWithDuration(t, s); case 11: return ZoomFlipYUpOver::transitionWithDuration(t, s);
case 12: return ZoomFlipYDownOver::transitionWithDuration(t, s); case 12: return ZoomFlipYDownOver::transitionWithDuration(t, s);
case 13: return ZoomFlipAngularLeftOver::transitionWithDuration(t, s); case 13: return ZoomFlipAngularLeftOver::transitionWithDuration(t, s);
case 14: return ZoomFlipAngularRightOver::transitionWithDuration(t, s); case 14: return ZoomFlipAngularRightOver::transitionWithDuration(t, s);
case 15: return CCTransitionShrinkGrow::transitionWithDuration(t, s); case 15: return CCTransitionShrinkGrow::transitionWithDuration(t, s);
case 16: return CCTransitionRotoZoom::transitionWithDuration(t, s); case 16: return CCTransitionRotoZoom::transitionWithDuration(t, s);
case 17: return CCTransitionMoveInL::transitionWithDuration(t, s); case 17: return CCTransitionMoveInL::transitionWithDuration(t, s);
@ -213,36 +213,39 @@ CCTransitionScene* createTransition(int nIndex, ccTime t, CCScene* s)
case 23: return CCTransitionSlideInT::transitionWithDuration(t, s); case 23: return CCTransitionSlideInT::transitionWithDuration(t, s);
case 24: return CCTransitionSlideInB::transitionWithDuration(t, s); case 24: return CCTransitionSlideInB::transitionWithDuration(t, s);
case 25: return CCTransitionCrossFade::transitionWithDuration(t,s); case 25: return CCTransitionCrossFade::transitionWithDuration(t,s);
case 26: return CCTransitionRadialCCW::transitionWithDuration(t,s); case 26: return CCTransitionRadialCCW::transitionWithDuration(t,s);
case 27: return CCTransitionRadialCW::transitionWithDuration(t,s); case 27: return CCTransitionRadialCW::transitionWithDuration(t,s);
case 28: return PageTransitionForward::transitionWithDuration(t, s); case 28: return PageTransitionForward::transitionWithDuration(t, s);
case 29: return PageTransitionBackward::transitionWithDuration(t, s); case 29: return PageTransitionBackward::transitionWithDuration(t, s);
case 30: return CCTransitionFadeTR::transitionWithDuration(t, s); case 30: return CCTransitionFadeTR::transitionWithDuration(t, s);
case 31: return CCTransitionFadeBL::transitionWithDuration(t, s); case 31: return CCTransitionFadeBL::transitionWithDuration(t, s);
case 32: return CCTransitionFadeUp::transitionWithDuration(t, s); case 32: return CCTransitionFadeUp::transitionWithDuration(t, s);
case 33: return CCTransitionFadeDown::transitionWithDuration(t, s); case 33: return CCTransitionFadeDown::transitionWithDuration(t, s);
case 34: return CCTransitionTurnOffTiles::transitionWithDuration(t, s); case 34: return CCTransitionTurnOffTiles::transitionWithDuration(t, s);
case 35: return CCTransitionSplitRows::transitionWithDuration(t, s); case 35: return CCTransitionSplitRows::transitionWithDuration(t, s);
case 36: return CCTransitionSplitCols::transitionWithDuration(t, s); case 36: return CCTransitionSplitCols::transitionWithDuration(t, s);
default: break; default: break;
} }
return NULL; return NULL;
} }
void TransitionsTestScene::runThisTest() void TransitionsTestScene::runThisTest()
{ {
CCLayer * pLayer = new TestLayer1(); CCLayer * pLayer = new TestLayer1();
addChild(pLayer); addChild(pLayer);
pLayer->release(); pLayer->release();
CCDirector::sharedDirector()->replaceScene(this); // fix bug #486, without setDepthTest(false), FlipX,Y will flickers
} CCDirector::sharedDirector()->setDepthTest(false);
TestLayer1::TestLayer1(void) CCDirector::sharedDirector()->replaceScene(this);
{ }
TestLayer1::TestLayer1(void)
{
float x,y; float x,y;
CCSize size = CCDirector::sharedDirector()->getWinSize(); CCSize size = CCDirector::sharedDirector()->getWinSize();
@ -250,7 +253,7 @@ TestLayer1::TestLayer1(void)
y = size.height; y = size.height;
CCSprite* bg1 = CCSprite::spriteWithFile(s_back1); CCSprite* bg1 = CCSprite::spriteWithFile(s_back1);
bg1->setPosition( CCPointMake(size.width/2, size.height/2) ); bg1->setPosition( CCPointMake(size.width/2, size.height/2) );
addChild(bg1, -1); addChild(bg1, -1);
CCLabelTTF* title = CCLabelTTF::labelWithString( (transitions[s_nSceneIdx]).c_str(), "Thonburi", 32 ); CCLabelTTF* title = CCLabelTTF::labelWithString( (transitions[s_nSceneIdx]).c_str(), "Thonburi", 32 );
@ -264,8 +267,8 @@ TestLayer1::TestLayer1(void)
addChild( label); addChild( label);
// menu // menu
CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(TestLayer1::backCallback) ); CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(TestLayer1::backCallback) );
CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(TestLayer1::restartCallback) ); CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(TestLayer1::restartCallback) );
CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(TestLayer1::nextCallback) ); CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(TestLayer1::nextCallback) );
CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL); CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);
@ -278,13 +281,13 @@ TestLayer1::TestLayer1(void)
addChild(menu, 1); addChild(menu, 1);
schedule( schedule_selector(TestLayer1::step), 1.0f); schedule( schedule_selector(TestLayer1::step), 1.0f);
} }
TestLayer1::~TestLayer1(void) TestLayer1::~TestLayer1(void)
{ {
} }
void TestLayer1::restartCallback(CCObject* pSender) void TestLayer1::restartCallback(CCObject* pSender)
{ {
CCScene* s = new TransitionsTestScene(); CCScene* s = new TransitionsTestScene();
@ -295,9 +298,9 @@ void TestLayer1::restartCallback(CCObject* pSender)
CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s); CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
s->release(); s->release();
pLayer->release(); pLayer->release();
if (pScene) if (pScene)
{ {
CCDirector::sharedDirector()->replaceScene(pScene); CCDirector::sharedDirector()->replaceScene(pScene);
} }
} }
@ -314,19 +317,19 @@ void TestLayer1::nextCallback(CCObject* pSender)
CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s); CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
s->release(); s->release();
pLayer->release(); pLayer->release();
if (pScene) if (pScene)
{ {
CCDirector::sharedDirector()->replaceScene(pScene); CCDirector::sharedDirector()->replaceScene(pScene);
} }
} }
void TestLayer1::backCallback(CCObject* pSender) void TestLayer1::backCallback(CCObject* pSender)
{ {
s_nSceneIdx--; s_nSceneIdx--;
int total = MAX_LAYER; int total = MAX_LAYER;
if( s_nSceneIdx < 0 ) if( s_nSceneIdx < 0 )
s_nSceneIdx += total; s_nSceneIdx += total;
CCScene* s = new TransitionsTestScene(); CCScene* s = new TransitionsTestScene();
CCLayer* pLayer = new TestLayer2(); CCLayer* pLayer = new TestLayer2();
@ -335,19 +338,19 @@ void TestLayer1::backCallback(CCObject* pSender)
CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s); CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
s->release(); s->release();
pLayer->release(); pLayer->release();
if (pScene) if (pScene)
{ {
CCDirector::sharedDirector()->replaceScene(pScene); CCDirector::sharedDirector()->replaceScene(pScene);
} }
} }
void TestLayer1::step(ccTime dt) void TestLayer1::step(ccTime dt)
{ {
} }
TestLayer2::TestLayer2() TestLayer2::TestLayer2()
{ {
float x,y; float x,y;
CCSize size = CCDirector::sharedDirector()->getWinSize(); CCSize size = CCDirector::sharedDirector()->getWinSize();
@ -355,7 +358,7 @@ TestLayer2::TestLayer2()
y = size.height; y = size.height;
CCSprite* bg1 = CCSprite::spriteWithFile(s_back2); CCSprite* bg1 = CCSprite::spriteWithFile(s_back2);
bg1->setPosition( CCPointMake(size.width/2, size.height/2) ); bg1->setPosition( CCPointMake(size.width/2, size.height/2) );
addChild(bg1, -1); addChild(bg1, -1);
CCLabelTTF* title = CCLabelTTF::labelWithString((transitions[s_nSceneIdx]).c_str(), "Thonburi", 32 ); CCLabelTTF* title = CCLabelTTF::labelWithString((transitions[s_nSceneIdx]).c_str(), "Thonburi", 32 );
@ -369,8 +372,8 @@ TestLayer2::TestLayer2()
addChild( label); addChild( label);
// menu // menu
CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(TestLayer2::backCallback) ); CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(TestLayer2::backCallback) );
CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(TestLayer2::restartCallback) ); CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(TestLayer2::restartCallback) );
CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(TestLayer2::nextCallback) ); CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(TestLayer2::nextCallback) );
CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL); CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);
@ -382,14 +385,14 @@ TestLayer2::TestLayer2()
addChild(menu, 1); addChild(menu, 1);
schedule(schedule_selector(TestLayer2::step), 1.0f); schedule(schedule_selector(TestLayer2::step), 1.0f);
} }
TestLayer2::~TestLayer2() TestLayer2::~TestLayer2()
{ {
} }
void TestLayer2::restartCallback(CCObject* pSender) void TestLayer2::restartCallback(CCObject* pSender)
{ {
CCScene* s = new TransitionsTestScene(); CCScene* s = new TransitionsTestScene();
@ -400,9 +403,9 @@ void TestLayer2::restartCallback(CCObject* pSender)
CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s); CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
s->release(); s->release();
pLayer->release(); pLayer->release();
if (pScene) if (pScene)
{ {
CCDirector::sharedDirector()->replaceScene(pScene); CCDirector::sharedDirector()->replaceScene(pScene);
} }
} }
@ -419,19 +422,19 @@ void TestLayer2::nextCallback(CCObject* pSender)
CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s); CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
s->release(); s->release();
pLayer->release(); pLayer->release();
if (pScene) if (pScene)
{ {
CCDirector::sharedDirector()->replaceScene(pScene); CCDirector::sharedDirector()->replaceScene(pScene);
} }
} }
void TestLayer2::backCallback(CCObject* pSender) void TestLayer2::backCallback(CCObject* pSender)
{ {
s_nSceneIdx--; s_nSceneIdx--;
int total = MAX_LAYER; int total = MAX_LAYER;
if( s_nSceneIdx < 0 ) if( s_nSceneIdx < 0 )
s_nSceneIdx += total; s_nSceneIdx += total;
CCScene* s = new TransitionsTestScene(); CCScene* s = new TransitionsTestScene();
CCLayer* pLayer = new TestLayer1(); CCLayer* pLayer = new TestLayer1();
@ -440,13 +443,13 @@ void TestLayer2::backCallback(CCObject* pSender)
CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s); CCScene* pScene = createTransition(s_nSceneIdx, TRANSITION_DURATION, s);
s->release(); s->release();
pLayer->release(); pLayer->release();
if (pScene) if (pScene)
{ {
CCDirector::sharedDirector()->replaceScene(pScene); CCDirector::sharedDirector()->replaceScene(pScene);
} }
} }
void TestLayer2::step(ccTime dt) void TestLayer2::step(ccTime dt)
{ {
} }