0

このコードを使用して、ボールを作成して投げます。ボールの速度を上げたいのですが、破壊されるまで速度を維持する必要があります。結果を得るにはどうすればよいですか?

            var sphereShape:b2CircleShape=new b2CircleShape(15/worldScale);
            var sphereFixture:b2FixtureDef = new b2FixtureDef();
            sphereFixture.density=1;
            sphereFixture.friction=3;
            sphereFixture.restitution=0.1;
            sphereFixture.filter.groupIndex = -1;
            sphereFixture.shape=sphereShape;
            ball_mc=new ballMc();
            ballCont_mc.addChild(ball_mc);
            var sphereBodyDef:b2BodyDef = new b2BodyDef();
            sphereBodyDef.type=b2Body.b2_dynamicBody;
            ball_mc.name="throwBall";
            ball_mc.hitCount=0;
            ball_mc.basketHit=0;
            sphereBodyDef.position.Set(arrow_mc.x/worldScale,arrow_mc.y/worldScale);
            birdSphere=world.CreateBody(sphereBodyDef);
            birdSphere.CreateFixture(sphereFixture);girl_mc.gotoAndStop(3);
            birdSphere.SetUserData(ball_mc);
            birdSphere.SetBullet(true);
            var distanceX:Number=arrow_mc.x-mouseX;
            var distanceY:Number=arrow_mc.y-mouseY;
            var distance:Number=Math.sqrt(distanceX*distanceX+distanceY*distanceY);
            var birdAngle:Number=Math.atan2(distanceY,distanceX);
            birdSphere.SetLinearVelocity(new b2Vec2(distance*Math.cos(birdAngle)/4,distance*Math.sin(birdAngle)/4));

誰か助けてもらえますか?

4

1 に答える 1

3

ボールに Speed 変数を指定し、次のような関数を使用します。

function run(Self)
 {
   Self._x+=Math.sin(Self._rotation*(Math.PI/180))*Self.Speed/10;
   Self._y+=Math.cos(Self._rotation*(Math.PI/180))*Self.Speed/10*-1;
 }//------------------------------------------------------------^run

run(ball_mc); を呼び出します。動かしたいすべてのフレーム。

速度の場合と同様に、Speed 変数を維持します。

自己は単なるボールです。最初に、移動する方向に応じて回転を設定する必要がありますが、それは別のトピックなので、スペースを節約してその部分を省略します.

これが役立つことを願っています。

于 2012-08-20T08:02:05.527 に答える