Sairin 2014-03-18 09:45 采纳率: 0%
浏览 1958

cocos2dx 图片的多点触控缩放

#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)
{

}

在手机上测试的时候发现只要一点屏幕就黑了,请问是什么问题

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog