我是 Cocos2d 和 Box2d 的新手,我有一些问题要问你。在开发或尝试玩游戏时,我将动态身体拖到边界(到我的 ipone 的框架),并且发生了一些事情,我的动态身体的一半超出了框架!我不知道为什么?请尽快帮助我!
问问题
77 次
1 回答
0
我解决了。我将以下代码写入 ccTouchesMoved 函数。
CGSize s = [[CCDirector sharedDirector] winSize];
// Update if it is moved
CGPoint location = [tj.touch locationInView:tj.touch.view];
location = [[CCDirector sharedDirector] convertToGL:location];
int deger=50; // mydynamicbody width
float xcordinate=location.x;
float ycordinate=location.y;
if (xcordinate>(s.width-deger))
{
xcordinate=s.width-deger;
}
if (ycordinate>(s.height-deger))
{
ycordinate=s.height-deger;
}
if (xcordinate<deger)
{
xcordinate=deger;
}
if(ycordinate<deger)
{
ycordinate=deger;
}
// NSLog(@"cordinates %f , %f %g %g",xcordinate,ycordinate,s.width,s.height);
b2Vec2 worldLocation = b2Vec2(ptm(xcordinate),ptm(ycordinate) );
//b2Vec2 worldLocation = b2Vec2(200, 200);
tj.mouseJoint->SetTarget(worldLocation);
于 2012-10-12T20:39:11.480 回答