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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)
    • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。