MyTetra Share
Делитесь знаниями!
Использование MouseJoin
Время создания: 27.11.2017 14:47
Раздел: Компьютер - Программирование - Физические движки - Box2D
Запись: xintrea/mytetra_syncro/master/base/1511783273iuknymwc5g/text.html на raw.github.com

Настройки

self.touchEnabled = YES;

Then add the following member variable to your HelloWorld class in HelloWorldLayer.h:

b2MouseJoint *_mouseJoint;

Now let’s implement the touch methods! Let’s start with ccTouchesBegan:

- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

if (_mouseJoint != NULL) return;

UITouch *myTouch = [touches anyObject];

CGPoint location = [myTouch locationInView:[myTouch view]];

location = [[CCDirector sharedDirector] convertToGL:location];

b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);

if (_paddleFixture->TestPoint(locationWorld)) {

b2MouseJointDef md;

md.bodyA = _groundBody;

md.bodyB = _paddleBody;

md.target = locationWorld;

md.collideConnected = true;

md.maxForce = 1000.0f * _paddleBody->GetMass();

_mouseJoint = (b2MouseJoint *)_world->CreateJoint(&md);

_paddleBody->SetAwake(true);

}

}


-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

if (_mouseJoint == NULL) return;

UITouch *myTouch = [touches anyObject];

CGPoint location = [myTouch locationInView:[myTouch view]];

location = [[CCDirector sharedDirector] convertToGL:location];

b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO);

_mouseJoint->SetTarget(locationWorld);

}



 
MyTetra Share v.0.65
Яндекс индекс цитирования