fixed #574, Add bugs test case.

This commit is contained in:
natural-law 2011-07-08 11:22:35 +08:00
parent 26513d6b7e
commit ca4281904a
27 changed files with 1127 additions and 5 deletions

View File

@ -0,0 +1 @@
6b9dcb4915a36e3aefef3f153949a96b145fba0d

View File

@ -975,6 +975,102 @@
>
</File>
</Filter>
<Filter
Name="BugsTest"
>
<File
RelativePath="..\tests\BugsTest\Bug-1159.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-1159.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-1174.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-1174.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-350.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-350.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-422.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-422.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-624.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-624.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-886.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-886.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-899.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-899.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-914.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-914.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\BugsTest.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\BugsTest.h"
>
</File>
<Filter
Name="Bug-458"
>
<File
RelativePath="..\tests\BugsTest\Bug-458\Bug-458.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-458\Bug-458.h"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-458\QuestionContainerSprite.cpp"
>
</File>
<File
RelativePath="..\tests\BugsTest\Bug-458\QuestionContainerSprite.h"
>
</File>
</Filter>
</Filter>
</Filter>
</Filter>
</Files>

View File

@ -0,0 +1,61 @@
//
// Bug-1159.m
// Z-Fighting in iPad 2
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=1159
//
// Created by Greg Woods on 4/5/11.
// Copyright 2011 Westlake Design. All rights reserved.
//
#include "Bug-1159.h"
CCScene* Bug1159Layer::scene()
{
CCScene *pScene = CCScene::node();
Bug1159Layer* layer = Bug1159Layer::node();
pScene->addChild(layer);
return pScene;
}
bool Bug1159Layer::init()
{
if (BugsTestBaseLayer::init())
{
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLayerColor *background = CCLayerColor::layerWithColor(ccc4(255, 0, 255, 255));
addChild(background);
CCLayerColor *sprite_a = CCLayerColor::layerWithColorWidthHeight(ccc4(255, 0, 0, 255), 700, 700);
sprite_a->setAnchorPoint(ccp(0.5f, 0.5f));
sprite_a->setIsRelativeAnchorPoint(true);
sprite_a->setPosition(ccp(0.0, s.height/2));
addChild(sprite_a);
sprite_a->runAction(CCRepeatForever::actionWithAction((CCActionInterval*) CCSequence::actions(
CCMoveTo::actionWithDuration(1.0f, ccp(1024.0, 384.0)),
CCMoveTo::actionWithDuration(1.0f, ccp(0.0, 384.0)),
NULL)));
CCLayerColor *sprite_b = CCLayerColor::layerWithColorWidthHeight(ccc4(0, 0, 255, 255), 400, 400);
sprite_b->setAnchorPoint(ccp(0.5f, 0.5f));
sprite_b->setIsRelativeAnchorPoint(true);
sprite_b->setPosition(ccp(s.width/2, s.height/2));
addChild(sprite_b);
CCMenuItemLabel *label = CCMenuItemLabel::itemWithLabel(CCLabelTTF::labelWithString("Flip Me", "Helvetica", 24), this, menu_selector(Bug1159Layer::callBack));
CCMenu *menu = CCMenu::menuWithItems(label, NULL);
menu->setPosition(ccp(s.width - 200, 50.0));
addChild(menu);
return true;
}
return false;
}
void Bug1159Layer::callBack(CCObject* pSender)
{
CCDirector::sharedDirector()->replaceScene(CCTransitionPageTurn::transitionWithDuration(1.0f, Bug1159Layer::scene(), false));
}

View File

@ -0,0 +1,16 @@
#ifndef __BUG_1159_H__
#define __BUG_1159_H__
#include "BugsTest.h"
class Bug1159Layer : public BugsTestBaseLayer
{
public:
virtual bool init();
static CCScene* scene();
void callBack(CCObject* pSender);
LAYER_NODE_FUNC(Bug1159Layer);
};
#endif // __BUG_1159_H__

View File

@ -0,0 +1,159 @@
//
// Bug-1174
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=1174
//
#include "Bug-1174.h"
int check_for_error( CCPoint p1, CCPoint p2, CCPoint p3, CCPoint p4, float s, float t )
{
// the hit point is p3 + t * (p4 - p3);
// the hit point also is p1 + s * (p2 - p1);
CCPoint p4_p3 = ccpSub( p4, p3);
CCPoint p4_p3_t = ccpMult(p4_p3, t);
CCPoint hitPoint1 = ccpAdd( p3, p4_p3_t);
CCPoint p2_p1 = ccpSub( p2, p1);
CCPoint p2_p1_s = ccpMult(p2_p1, s);
CCPoint hitPoint2 = ccpAdd( p1, p2_p1_s);
// Since float has rounding errors, only check if diff is < 0.05
if( (fabs( hitPoint1.x - hitPoint2.x) > 0.1f) || ( fabs(hitPoint1.y - hitPoint2.y) > 0.1f) )
{
CCLog("ERROR: (%f,%f) != (%f,%f)", hitPoint1.x, hitPoint1.y, hitPoint2.x, hitPoint2.y);
return 1;
}
return 0;
}
bool Bug1174Layer::init()
{
if (BugsTestBaseLayer::init())
{
// // seed
// srand(0);
CCPoint A,B,C,D,p1,p2,p3,p4;
float s,t;
int err=0;
int ok=0;
//
// Test 1.
//
CCLog("Test1 - Start");
for( int i=0; i < 10000; i++)
{
// A | b
// -----
// c | d
float ax = CCRANDOM_0_1() * -5000;
float ay = CCRANDOM_0_1() * 5000;
// a | b
// -----
// c | D
float dx = CCRANDOM_0_1() * 5000;
float dy = CCRANDOM_0_1() * -5000;
// a | B
// -----
// c | d
float bx = CCRANDOM_0_1() * 5000;
float by = CCRANDOM_0_1() * 5000;
// a | b
// -----
// C | d
float cx = CCRANDOM_0_1() * -5000;
float cy = CCRANDOM_0_1() * -5000;
A = ccp(ax,ay);
B = ccp(bx,by);
C = ccp(cx,cy);
D = ccp(dx,dy);
if( ccpLineIntersect( A, D, B, C, &s, &t) ) {
if( check_for_error(A, D, B, C, s, t) )
err++;
else
ok++;
}
}
CCLog("Test1 - End. OK=%i, Err=%i", ok, err);
//
// Test 2.
//
CCLog("Test2 - Start");
p1 = ccp(220,480);
p2 = ccp(304,325);
p3 = ccp(264,416);
p4 = ccp(186,416);
s = 0.0f;
t = 0.0f;
if( ccpLineIntersect(p1, p2, p3, p4, &s, &t) )
check_for_error(p1, p2, p3, p4, s,t );
CCLog("Test2 - End");
//
// Test 3
//
CCLog("Test3 - Start");
ok=0;
err=0;
for( int i=0;i<10000;i++)
{
// A | b
// -----
// c | d
float ax = CCRANDOM_0_1() * -500;
float ay = CCRANDOM_0_1() * 500;
p1 = ccp(ax,ay);
// a | b
// -----
// c | D
float dx = CCRANDOM_0_1() * 500;
float dy = CCRANDOM_0_1() * -500;
p2 = ccp(dx,dy);
//////
float y = ay - ((ay - dy) /2.0f);
// a | b
// -----
// C | d
float cx = CCRANDOM_0_1() * -500;
p3 = ccp(cx,y);
// a | B
// -----
// c | d
float bx = CCRANDOM_0_1() * 500;
p4 = ccp(bx,y);
s = 0.0f;
t = 0.0f;
if( ccpLineIntersect(p1, p2, p3, p4, &s, &t) ) {
if( check_for_error(p1, p2, p3, p4, s,t ) )
err++;
else
ok++;
}
}
CCLog("Test3 - End. OK=%i, err=%i", ok, err);
return true;
}
return false;
}

View File

@ -0,0 +1,12 @@
#ifndef __BUG_1174_H__
#define __BUG_1174_H__
#include "BugsTest.h"
class Bug1174Layer : public BugsTestBaseLayer
{
public:
virtual bool init();
};
#endif // __BUG_1174_H__

View File

@ -0,0 +1,20 @@
//
// Bug-350
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=350
//
#include "Bug-350.h"
bool Bug350Layer::init()
{
if (BugsTestBaseLayer::init())
{
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSprite *background = CCSprite::spriteWithFile("Default.png");
background->setPosition(ccp(size.width/2, size.height/2));
addChild(background);
return true;
}
return false;
}

View File

@ -0,0 +1,12 @@
#ifndef __BUG_350_H__
#define __BUG_350_H__
#include "BugsTest.h"
class Bug350Layer : public BugsTestBaseLayer
{
public:
virtual bool init();
};
#endif // __BUG_350_H__

View File

@ -0,0 +1,64 @@
//
// Bug-422 test case by lhunath
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=422
//
#include "Bug-422.h"
bool Bug422Layer::init()
{
if (BugsTestBaseLayer::init())
{
reset();
return true;
}
return false;
}
void Bug422Layer::reset()
{
static int localtag = 0;
localtag++;
// TO TRIGGER THE BUG:
// remove the itself from parent from an action
// The menu will be removed, but the instance will be alive
// and then a new node will be allocated occupying the memory.
// => CRASH BOOM BANG
CCNode *node = getChildByTag(localtag-1);
CCLog("Menu: %p", node);
removeChild(node, false);
// [self removeChildByTag:localtag-1 cleanup:NO];
CCMenuItem *item1 = CCMenuItemFont::itemFromString("One", this, menu_selector(Bug422Layer::menuCallback));
CCLog("MenuItemFont: %p", item1);
CCMenuItem *item2 = CCMenuItemFont::itemFromString("Two", this, menu_selector(Bug422Layer::menuCallback));
CCMenu *menu = CCMenu::menuWithItems(item1, item2, NULL);
menu->alignItemsVertically();
float x = CCRANDOM_0_1() * 50;
float y = CCRANDOM_0_1() * 50;
menu->setPosition(ccpAdd( menu->getPosition(), ccp(x,y)));
addChild(menu, 0, localtag);
//[self check:self];
}
void Bug422Layer::check(CCNode* t)
{
CCArray *array = t->getChildren();
CCObject* pChild = NULL;
CCARRAY_FOREACH(array, pChild)
{
CC_BREAK_IF(! pChild);
CCNode* pNode = (CCNode*) pChild;
CCLog("%p, rc: %d", pNode, pNode->retainCount());
check(pNode);
}
}
void Bug422Layer::menuCallback(CCObject* sender)
{
reset();
}

View File

@ -0,0 +1,16 @@
#ifndef __BUG_422_H__
#define __BUG_422_H__
#include "BugsTest.h"
class Bug422Layer : public BugsTestBaseLayer
{
public:
virtual bool init();
void reset();
void check(CCNode* target);
void menuCallback(CCObject* sender);
};
#endif // __BUG_422_H__

View File

@ -0,0 +1,46 @@
//
// Bug-458 test case by nedrafehi
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=458
//
#include "Bug-458.h"
#include "QuestionContainerSprite.h"
bool Bug458Layer::init()
{
if(BugsTestBaseLayer::init())
{
// ask director the the window size
CCSize size = CCDirector::sharedDirector()->getWinSize();
QuestionContainerSprite* question = new QuestionContainerSprite();
QuestionContainerSprite* question2 = new QuestionContainerSprite();
question->init();
question2->init();
// [question setContentSize:CGSizeMake(50,50)];
// [question2 setContentSize:CGSizeMake(50,50)];
CCMenuItemSprite* sprite = CCMenuItemSprite::itemFromNormalSprite(question2, question, this, menu_selector(Bug458Layer::selectAnswer));
CCLayerColor* layer = CCLayerColor::layerWithColorWidthHeight(ccc4(0,0,255,255), 100, 100);
question->release();
question2->release();
CCLayerColor* layer2 = CCLayerColor::layerWithColorWidthHeight(ccc4(255,0,0,255), 100, 100);
CCMenuItemSprite* sprite2 = CCMenuItemSprite::itemFromNormalSprite(layer, layer2, this, menu_selector(Bug458Layer::selectAnswer));
CCMenu* menu = CCMenu::menuWithItems(sprite, sprite2, NULL);
menu->alignItemsVerticallyWithPadding(100);
menu->setPosition(ccp(size.width / 2, size.height / 2));
// add the label as a child to this Layer
addChild(menu);
return true;
}
return false;
}
void Bug458Layer::selectAnswer(CCObject* sender)
{
CCLog("Selected");
}

View File

@ -0,0 +1,13 @@
#ifndef __BUG_458_H__
#define __BUG_458_H__
#include "../BugsTest.h"
class Bug458Layer : public BugsTestBaseLayer
{
public:
virtual bool init();
void selectAnswer(CCObject* sender);
};
#endif // __BUG_458_H__

View File

@ -0,0 +1,86 @@
#include "QuestionContainerSprite.h"
#define kLabelTag
using namespace cocos2d;
bool QuestionContainerSprite::init()
{
if (CCSprite::init())
{
//Add label
CCLabelTTF* label = CCLabelTTF::labelWithString("Answer 1", "Arial", 12);
label->setTag(100);
//Add the background
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSprite* corner = CCSprite::spriteWithFile("Images/bugs/corner.png");
int width = size.width * 0.9f - (corner->getContentSize().width * 2);
int height = size.height * 0.15f - (corner->getContentSize().height * 2);
CCLayerColor* layer = CCLayerColor::layerWithColorWidthHeight(ccc4(255, 255, 255, 255 * .75), width, height);
layer->setPosition(ccp(-width / 2, -height / 2));
//First button is blue,
//Second is red
//Used for testing - change later
static int a = 0;
if (a == 0)
label->setColor(ccBLUE);
else
{
CCLog("Color changed");
label->setColor(ccRED);
}
a++;
addChild(layer);
corner->setPosition(ccp(-(width / 2 + corner->getContentSize().width / 2), -(height / 2 + corner->getContentSize().height / 2)));
addChild(corner);
CCSprite* corner2 = CCSprite::spriteWithFile("Images/bugs/corner.png");
corner2->setPosition(ccp(-corner->getPosition().x, corner->getPosition().y));
corner2->setFlipX(true);
addChild(corner2);
CCSprite* corner3 = CCSprite::spriteWithFile("Images/bugs/corner.png");
corner3->setPosition(ccp(corner->getPosition().x, -corner->getPosition().y));
corner3->setFlipY(true);
addChild(corner3);
CCSprite* corner4 = CCSprite::spriteWithFile("Images/bugs/corner.png");
corner4->setPosition(ccp(corner2->getPosition().x, -corner2->getPosition().y));
corner4->setFlipX(true);
corner4->setFlipY(true);
addChild(corner4);
CCSprite* edge = CCSprite::spriteWithFile("Images/bugs/edge.png");
edge->setScaleX(width);
edge->setPosition(ccp(corner->getPosition().x + (corner->getContentSize().width / 2) + (width / 2), corner->getPosition().y));
addChild(edge);
CCSprite* edge2 = CCSprite::spriteWithFile("Images/bugs/edge.png");
edge2->setScaleX(width);
edge2->setPosition(ccp(corner->getPosition().x + (corner->getContentSize().width / 2) + (width / 2), -corner->getPosition().y));
edge2->setFlipY(true);
addChild(edge2);
CCSprite* edge3 = CCSprite::spriteWithFile("Images/bugs/edge.png");
edge3->setRotation(90);
edge3->setScaleX(height);
edge3->setPosition(ccp(corner->getPosition().x, corner->getPosition().y + (corner->getContentSize().height / 2) + (height / 2)));
addChild(edge3);
CCSprite* edge4 = CCSprite::spriteWithFile("Images/bugs/edge.png");
edge4->setRotation(270);
edge4->setScaleX(height);
edge4->setPosition(ccp(-corner->getPosition().x, corner->getPosition().y + (corner->getContentSize().height / 2) + (height / 2)));
addChild(edge4);
addChild(label);
return true;
}
return false;
}

View File

@ -0,0 +1,12 @@
#ifndef __QUESTION_CONTAINER_SPRITE_H__
#define __QUESTION_CONTAINER_SPRITE_H__
#include "cocos2d.h"
class QuestionContainerSprite : public cocos2d::CCSprite
{
public:
virtual bool init();
};
#endif // __QUESTION_CONTAINER_SPRITE_H__

View File

@ -0,0 +1,80 @@
//
// Bug-624
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=624
//
#include "Bug-624.h"
////////////////////////////////////////////////////////
//
// Bug624Layer
//
////////////////////////////////////////////////////////
bool Bug624Layer::init()
{
if(BugsTestBaseLayer::init())
{
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF *label = CCLabelTTF::labelWithString("Layer1", "Marker Felt", 36);
label->setPosition(ccp(size.width/2, size.height/2));
addChild(label);
setIsAccelerometerEnabled(true);
schedule(schedule_selector(Bug624Layer::switchLayer), 5.0f);
return true;
}
return false;
}
void Bug624Layer::switchLayer(ccTime dt)
{
unschedule(schedule_selector(Bug624Layer::switchLayer));
CCScene *scene = CCScene::node();
scene->addChild(Bug624Layer2::node(), 0);
CCDirector::sharedDirector()->replaceScene(CCTransitionFade::transitionWithDuration(2.0f, scene, ccWHITE));
}
void Bug624Layer::didAccelerate(CCAcceleration* acceleration)
{
CCLog("Layer1 accel");
}
////////////////////////////////////////////////////////
//
// Bug624Layer2
//
////////////////////////////////////////////////////////
bool Bug624Layer2::init()
{
if(BugsTestBaseLayer::init())
{
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF *label = CCLabelTTF::labelWithString("Layer2", "Marker Felt", 36);
label->setPosition(ccp(size.width/2, size.height/2));
addChild(label);
setIsAccelerometerEnabled(true);
schedule(schedule_selector(Bug624Layer2::switchLayer), 5.0f);
return true;
}
return false;
}
void Bug624Layer2::switchLayer(ccTime dt)
{
unschedule(schedule_selector(Bug624Layer::switchLayer));
CCScene *scene = CCScene::node();
scene->addChild(Bug624Layer::node(), 0);
CCDirector::sharedDirector()->replaceScene(CCTransitionFade::transitionWithDuration(2.0f, scene, ccRED));
}
void Bug624Layer2::didAccelerate(CCAcceleration* acceleration)
{
CCLog("Layer2 accel");
}

View File

@ -0,0 +1,26 @@
#ifndef __BUG_624_H__
#define __BUG_624_H__
#include "BugsTest.h"
class Bug624Layer : public BugsTestBaseLayer
{
public:
virtual bool init();
void switchLayer(ccTime dt);
virtual void didAccelerate(CCAcceleration* pAccelerationValue);
LAYER_NODE_FUNC(Bug624Layer);
};
class Bug624Layer2 : public BugsTestBaseLayer
{
public:
virtual bool init();
void switchLayer(ccTime dt);
virtual void didAccelerate(CCAcceleration* pAccelerationValue);
LAYER_NODE_FUNC(Bug624Layer2);
};
#endif // __BUG_624_H__

View File

@ -0,0 +1,31 @@
//
// Bug-886
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=886
//
#include "Bug-886.h"
bool Bug886Layer::init()
{
if(BugsTestBaseLayer::init())
{
// ask director the the window size
// CGSize size = [[CCDirector sharedDirector] winSize];
CCSprite* sprite = CCSprite::spriteWithFile("Images/bugs/bug886.jpg");
sprite->setAnchorPoint(CCPointZero);
sprite->setPosition(CCPointZero);
sprite->setScaleX(0.6f);
addChild(sprite);
CCSprite* sprite2 = CCSprite::spriteWithFile("Images/bugs/bug886.png");
sprite2->setAnchorPoint(CCPointZero);
sprite2->setScaleX(0.6f);
sprite2->setPosition(ccp(sprite->getContentSize().width * 0.6f + 10, 0));
addChild(sprite2);
return true;
}
return false;
}

View File

@ -0,0 +1,12 @@
#ifndef __BUG_886_H__
#define __BUG_886_H__
#include "BugsTest.h"
class Bug886Layer : public BugsTestBaseLayer
{
public:
virtual bool init();
};
#endif // __BUG_886_H__

View File

@ -0,0 +1,27 @@
//
// Bug-899
// http://code.google.com/p/cocos2d-iphone/issues/detail?id=899
//
// Test coded by: JohnnyFlash
//
#include "Bug-899.h"
bool Bug899Layer::init()
{
CCDirector::sharedDirector()->enableRetinaDisplay(true);
if (BugsTestBaseLayer::init())
{
CCSprite *bg = CCSprite::spriteWithFile("Images/bugs/RetinaDisplay.jpg");
addChild(bg, 0);
bg->setAnchorPoint(CCPointZero);
return true;
}
return false;
}
Bug899Layer::~Bug899Layer()
{
CCDirector::sharedDirector()->enableRetinaDisplay(false);
}

View File

@ -0,0 +1,13 @@
#ifndef __BUG_899_H__
#define __BUG_899_H__
#include "BugsTest.h"
class Bug899Layer : public BugsTestBaseLayer
{
public:
virtual ~Bug899Layer();
virtual bool init();
};
#endif // __BUG_899_H__

View File

@ -0,0 +1,79 @@
//
// HelloWorldLayer.m
// EAGLViewBug
//
// Created by Wylan Werth on 7/5/10.
// Copyright BanditBear Games 2010. All rights reserved.
//
// Import the interfaces
#include"Bug-914.h"
CCScene* Bug914Layer::scene()
{
// 'scene' is an autorelease object.
CCScene *pScene = CCScene::node();
// 'layer' is an autorelease object.
Bug914Layer* layer = Bug914Layer::node();
// add layer as a child to scene
pScene->addChild(layer);
// return the scene
return pScene;
}
// on "init" you need to initialize your instance
bool Bug914Layer::init()
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if (BugsTestBaseLayer::init())
{
setIsTouchEnabled(true);
// ask director the the window size
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCLayerColor *layer;
for( int i=0;i < 5;i++)
{
layer = CCLayerColor::layerWithColor(ccc4(i*20, i*20, i*20,255));
layer->setContentSize(CCSizeMake(i*100, i*100));
layer->setPosition(ccp(size.width/2, size.height/2));
layer->setAnchorPoint(ccp(0.5f, 0.5f));
layer->setIsRelativeAnchorPoint(true);
addChild(layer, -1-i);
}
// create and initialize a Label
CCLabelTTF *label = CCLabelTTF::labelWithString("Hello World", "Marker Felt", 64);
CCMenuItem *item1 = CCMenuItemFont::itemFromString("restart", this, menu_selector(Bug914Layer::restart));
CCMenu *menu = CCMenu::menuWithItems(item1, NULL);
menu->alignItemsVertically();
menu->setPosition(ccp(size.width/2, 100));
addChild(menu);
// position the label on the center of the screen
label->setPosition(ccp( size.width /2 , size.height/2 ));
// add the label as a child to this Layer
addChild(label);
return true;
}
return false;
}
void Bug914Layer::ccTouchesMoved(CCSet *touches, CCEvent * event)
{
CCLog("Number of touches: %d", touches->count());
}
void Bug914Layer::ccTouchesBegan(CCSet *touches, CCEvent * event)
{
ccTouchesMoved(touches, event);
}
void Bug914Layer::restart(CCObject* sender)
{
CCDirector::sharedDirector()->replaceScene(Bug914Layer::scene());
}

View File

@ -0,0 +1,19 @@
#ifndef __BUG_914_H__
#define __BUG_914_H__
#include "BugsTest.h"
class Bug914Layer : public BugsTestBaseLayer
{
public:
static CCScene* scene();
virtual bool init();
void ccTouchesMoved(CCSet *touches, CCEvent * event);
void ccTouchesBegan(CCSet *touches, CCEvent * event);
void restart(CCObject* sender);
LAYER_NODE_FUNC(Bug914Layer);
};
#endif // __BUG_914_H__

View File

@ -0,0 +1,187 @@
#include "BugsTest.h"
#include "Bug-350.h"
#include "Bug-422.h"
#include "Bug-458/Bug-458.h"
#include "Bug-624.h"
#include "Bug-886.h"
#include "Bug-899.h"
#include "Bug-914.h"
#include "Bug-1159.h"
#include "Bug-1174.h"
#define TEST_BUG(bugNO) \
{ \
CCScene* pScene = CCScene::node(); \
Bug##bugNO##Layer* pLayer = new Bug##bugNO##Layer(); \
pLayer->init(); \
pScene->addChild(pLayer); \
CCDirector::sharedDirector()->replaceScene(pScene); \
pLayer->autorelease(); \
}
enum
{
MAX_COUNT = 9,
LINE_SPACE = 40,
kItemTagBasic = 5432,
};
static CCPoint s_tCurPos = CCPointZero;
const std::string testsName[MAX_COUNT] =
{
"Bug-350",
"Bug-422",
"Bug-458",
"Bug-624",
"Bug-886",
"Bug-899",
"Bug-914",
"Bug-1159",
"Bug-1174"
};
////////////////////////////////////////////////////////
//
// BugsTestMainLayer
//
////////////////////////////////////////////////////////
void BugsTestMainLayer::onEnter()
{
CCLayer::onEnter();
CCSize s = CCDirector::sharedDirector()->getWinSize();
m_pItmeMenu = CCMenu::menuWithItems(NULL);
m_pItmeMenu->setPosition( CCPointZero );
CCMenuItemFont::setFontName("Arial");
CCMenuItemFont::setFontSize(24);
for (int i = 0; i < MAX_COUNT; ++i)
{
CCMenuItemFont* pItem = CCMenuItemFont::itemFromString(testsName[i].c_str(), this,
menu_selector(BugsTestMainLayer::menuCallback));
pItem->setPosition(ccp(s.width / 2, s.height - (i + 1) * LINE_SPACE));
m_pItmeMenu->addChild(pItem, kItemTagBasic + i);
}
addChild(m_pItmeMenu);
setIsTouchEnabled(true);
}
void BugsTestMainLayer::menuCallback(CCObject* pSender)
{
CCMenuItemFont* pItem = (CCMenuItemFont*)pSender;
int nIndex = pItem->getZOrder() - kItemTagBasic;
switch (nIndex)
{
case 0:
TEST_BUG(350);
break;
case 1:
TEST_BUG(422);
break;
case 2:
TEST_BUG(458);
break;
case 3:
TEST_BUG(624);
break;
case 4:
TEST_BUG(886);
break;
case 5:
TEST_BUG(899);
break;
case 6:
TEST_BUG(914);
break;
case 7:
TEST_BUG(1159);
break;
case 8:
TEST_BUG(1174);
break;
default:
break;
}
}
void BugsTestMainLayer::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
CCSetIterator it = pTouches->begin();
CCTouch* touch = (CCTouch*)(*it);
m_tBeginPos = touch->locationInView( touch->view() );
m_tBeginPos = CCDirector::sharedDirector()->convertToGL( m_tBeginPos );
}
void BugsTestMainLayer::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent)
{
CCSetIterator it = pTouches->begin();
CCTouch* touch = (CCTouch*)(*it);
CCPoint touchLocation = touch->locationInView( touch->view() );
touchLocation = CCDirector::sharedDirector()->convertToGL( touchLocation );
float nMoveY = touchLocation.y - m_tBeginPos.y;
CCPoint curPos = m_pItmeMenu->getPosition();
CCPoint nextPos = ccp(curPos.x, curPos.y + nMoveY);
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
if (nextPos.y < 0.0f)
{
m_pItmeMenu->setPosition(CCPointZero);
return;
}
if (nextPos.y > ((MAX_COUNT + 1)* LINE_SPACE - winSize.height))
{
m_pItmeMenu->setPosition(ccp(0, ((MAX_COUNT + 1)* LINE_SPACE - winSize.height)));
return;
}
m_pItmeMenu->setPosition(nextPos);
m_tBeginPos = touchLocation;
s_tCurPos = nextPos;
}
////////////////////////////////////////////////////////
//
// BugsTestBaseLayer
//
////////////////////////////////////////////////////////
void BugsTestBaseLayer::onEnter()
{
CCLayer::onEnter();
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCMenuItemFont::setFontName("Arial");
CCMenuItemFont::setFontSize(24);
CCMenuItemFont* pMainItem = CCMenuItemFont::itemFromString("Back", this,
menu_selector(BugsTestBaseLayer::backCallback));
pMainItem->setPosition(ccp(s.width - 50, 25));
CCMenu* pMenu = CCMenu::menuWithItems(pMainItem, NULL);
pMenu->setPosition( CCPointZero );
addChild(pMenu);
}
void BugsTestBaseLayer::backCallback(CCObject* pSender)
{
BugsTestScene* pScene = new BugsTestScene();
pScene->runThisTest();
pScene->autorelease();
}
////////////////////////////////////////////////////////
//
// BugsTestScene
//
////////////////////////////////////////////////////////
void BugsTestScene::runThisTest()
{
CCLayer* pLayer = new BugsTestMainLayer();
addChild(pLayer);
pLayer->release();
CCDirector::sharedDirector()->replaceScene(this);
}

View File

@ -0,0 +1,33 @@
#ifndef __BUGS_TEST_H__
#define __BUGS_TEST_H__
#include "../testBasic.h"
class BugsTestMainLayer : public CCLayer
{
public:
virtual void onEnter();
void menuCallback(CCObject* pSender);
virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);
protected:
CCPoint m_tBeginPos;
CCMenu* m_pItmeMenu;
};
class BugsTestBaseLayer : public CCLayer
{
public:
virtual void onEnter();
void backCallback(CCObject* pSender);
};
class BugsTestScene : public TestScene
{
public:
virtual void runThisTest();
};
#endif

View File

@ -107,6 +107,8 @@ static TestScene* CreateTestScene(int nIdx)
#endif
case TEST_DIRECTOR:
pScene = new DirectorTestScene(); break;
case TEST_BUGS:
pScene = new BugsTestScene(); break;
default:
break;
}
@ -141,9 +143,6 @@ TestController::TestController()
m_pItmeMenu->addChild(pMenuItem, i + 10000);
pMenuItem->setPosition( CCPointMake( s.width / 2, (s.height - (i + 1) * LINE_SPACE) ));
// record the pointer of the menu item
m_pMenuItems[i] = pMenuItem;
}
m_pItmeMenu->setContentSize(CCSizeMake(s.width, (TESTS_COUNT + 1) * (LINE_SPACE)));

View File

@ -20,7 +20,6 @@ public:
private:
CCPoint m_tBeginPos;
CCMenuItemLabel * m_pMenuItems[TESTS_COUNT];
CCMenu* m_pItmeMenu;
};

View File

@ -40,6 +40,7 @@
#include "CurlTest/CurlTest.h"
#include "UserDefaultTest/UserDefaultTest.h"
#include "DirectorTest/DirectorTest.h"
#include "BugsTest/BugsTest.h"
#if (CC_TARGET_PLATFORM != CC_PLATFORM_AIRPLAY)
#include "ChipmunkTest/cocos2dChipmunkDemo.h"
@ -90,6 +91,7 @@ enum
TEST_CURL,
TEST_USERDEFAULT,
TEST_DIRECTOR,
TEST_BUGS,
TESTS_COUNT,
};
@ -131,7 +133,8 @@ const std::string g_aTestNames[TESTS_COUNT] = {
"ZwoptexTest",
"CurlTest",
"UserDefaultTest",
"DirectorTest"
"DirectorTest",
"BugsTest"
};
#endif