我是Cocos2d和Box2d的新手,我有一些问题要问你。 在开发或尝试玩游戏时,我将我的动态身体拖到边界(到我的ipone的框架),然后发生了一些事情,我的一半动态身体超出了框架!而且我不知道为什么?请尽快帮助我!
答案 0 :(得分: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);