#include "HelloWorld.h"
using namespace cocos2d;
CCScene* HelloWorld::scene()
{
CCScene * scene = NULL;
do
{
// 'scene' is an autorelease object
scene = CCScene::create();
CC_BREAK_IF(! scene);
// 'layer' is an autorelease object
HelloWorld *layer = HelloWorld::create();
CC_BREAK_IF(! layer);
// add layer as a child to scene
scene->addChild(layer);
} while (0);
// return the scene
return scene;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
bool bRet = false;
do
{
//////////////////////////////////////////////////////////////////////////
// super init first
//////////////////////////////////////////////////////////////////////////
CC_BREAK_IF(! CCLayer::init());
setTouchEnabled(true);
pSprite=CCSprite::create("map.jpg");
pSprite->setPosition(ccp(160,240));
this->addChild(pSprite);
mscale=1.0;
bRet = true;
} while (0);
return bRet;
}
void HelloWorld::registerWithTouchDispatcher(void)
{
CCDirector ::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this,0);
}
void HelloWorld::ccTouchesBegan(CCSet pTouches, CCEvent *pEvent)
{
if(pTouches->count()>=2)
{
CCSetIterator iter=pTouches->begin();
CCPoint mPoint1=((CCTouch)(*iter))->locationInView();
mPoint1=CCDirector::sharedDirector()->convertToGL(mPoint1);
iter ++;
CCPoint mPoint2 =((CCTouch*)(*iter))->locationInView();
mPoint2=CCDirector::sharedDirector()->convertToGL(mPoint2);
distance=sqrt((mPoint1.x-mPoint2.x)*(mPoint1.x-mPoint2.x)+(mPoint1.y-mPoint2.y)*(mPoint1.y-mPoint2.y));
deltax =(mPoint1.x+mPoint2.x)/2-pSprite->getPositionX();
deltay =(mPoint1.y+mPoint2.y)/2-pSprite->getPositionY();
}
}
void HelloWorld::ccTouchesMoved(CCSet pTouches, CCEvent *pEvent)
{
if(pTouches->count()>=2)
{
CCSetIterator iter=pTouches->begin();
CCPoint mPoint1=((CCTouch)(*iter))->locationInView();
mPoint1=CCDirector::sharedDirector()->convertToGL(mPoint1);
iter ++;
CCPoint mPoint2 =((CCTouch*)(*iter))->locationInView();
mPoint2=CCDirector::sharedDirector()->convertToGL(mPoint2);
double mdistance=sqrt((mPoint1.x-mPoint2.x)*(mPoint1.x-mPoint2.x)+(mPoint1.y-mPoint2.y)*(mPoint1.y-mPoint2.y));
mscale=mdistance/distance*mscale;
distance=mdistance;
pSprite->setScale(mscale);
double x=(mPoint1.x+mPoint2.x)/2-deltax;
double y=(mPoint1.y+mPoint2.y)/2-deltay;
pSprite->setPosition(ccp(x,y));
deltax=(mPoint1.x+mPoint2.x)/2-pSprite->getPositionX();
deltay=(mPoint1.y+mPoint2.y)/2-pSprite->getPositionY();
}
}
void HelloWorld::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{
}
void HelloWorld::ccTouchesCancelled(CCSet *pTouch, CCEvent *pEvent)
{
}
在手机上测试的时候发现只要一点屏幕就黑了,请问是什么问题