我是Cocos2d和Box2d的新手,我有几个问题要问你。在开发或尝试玩游戏时,我将我的动态身体拖动到边界(到我的ipone的框架),然后发生了一些事情,我的动态身体的一半超出了框架!我不知道为什么?请尽快帮我!
发布于 2012-10-13 04:39:11
我解决了这个问题,我把下面的代码写进了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); https://stackoverflow.com/questions/12848269
复制相似问题