我正在使用iOS
为cocos-2dx
开发游戏以提高性能,我已成功添加了chipmunk
正文但在运行时我的精灵正在屏幕上移动正文停留在原来的位置让我粘贴代码。
void TestGamePlay::onTouchesMoved(const std::vector<cocos2d::Touch *>&touches,cocos2d::Event *event)
{
auto touch = static_cast<Touch*>(touches[0]);
auto touchLocation = touch->getLocation();
cpVect v = cpv((touchLocation.x - littleFishBody->p.x) ,
(touchLocation.y - littleFishBody->p.y) );
v = cpv(250, 250);
cpBodyApplyImpulse(littleFishBody, v, cpv(0, 0));
cpBodyApplyForce(littleFishBody, v, cpv(0,0));
}
我在这里创造了身体。
`
float spriteWidth = sprite->getContentSize().width;
float spriteHeight = sprite->getContentSize().height;
spriteWidth = spriteWidth - factor;
spriteHeight = spriteHeight - factor;
int num = 4;
cpVect verts[] = { cpv(-13, -13), cpv(-13, 13), cpv(13, 13), cpv(13, -13) };
cpBody *body = cpBodyNew(1.0f,
cpMomentForPoly(1.0f, num, verts, cpv(0, 0)));
cpVect t;
t.x = point.x;
t.y = point.y;
cpBodySetPos(body, t);
cpSpaceAddBody(_space, body);
cpShape *shape = cpPolyShapeNew(body, num, verts, cpv(0, 0));
shape->data = sprite;
cpSpaceAddShape(_space, shape);
littleFishBody = body;
this->addChild(sprite, 3);
sprite->setCPBody(body);
` 请让我知道我在哪里出错了。