2012-09-14 45 views

回答

0

1.)檢測用戶觸摸的雲,增加身體的速度。要立即提高速度,請設置與雲有關的b2body的線速度。要逐漸提高速度,應用一種力量/衝動。例如:

在ccTouchesBegan

UITouch *touch = [touches anyObject]; 
CGPoint location = [touch locationInView:[touch view]]; 
location = [[CCDirector sharedDirector] convertToGL:location]; 
for(Cloud *cloud in clouds) { 

    if (CGRectContainsPoint(cloud.boudingBox, location)) { 

     b2Body *b = cloud.b2Body; 
     b2Vec2 *currentVelocity = b->GetLinearVelocity(); 
     b2Vec2 *newVelocity = b2Vec2(currentVelocity.x + addToSpeed, currentVelocity.y); 
     b->SetLinearVelocity(newVelocity); 

    } 

} 

2.)當雲b2body位置已經移動的更新方法的視圖外檢測。然後,你可以破壞雲體與子畫面,並創建在期望的位置一個新的,或者使用b2Body->的setTransform()到主體移動到新的位置與SetLinearVelocity(startingSpeed)

0

如何將雲從左向右移動?使用CCMoveTo或ApplyLinearVelocity?

如果是與CCMoveTo然後停止操作時用戶點擊,並再次用不同的速度運行CCMoveTo。