私はCocos2dを新しくしているので、ほとんどのクラスと関数を意識していません。私のアプリケーションでは、バレルの方向にボールを触れてドラッグするようなモジュールを実装して、ボールを通過させ、ボールをバレルに入れます。私は方向にボールを通過することができますが、座標(x.y)に続いて画面から出るだけです。私はそれがバレルの位置のアイデアを得るとバレルの上部を見つけて、ボールを動かしながらも、バレルの中央にボールを入れてます、の大きさになるような何かをする必要がありバケツにボールを投げるような効果を与えるには?
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
// Choose one of the touches to work with
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];
// Determine offset of location to projectile
int offX = location.x - ball.position.x;
int offY = location.y - ball.position.y;
// Bail out if we are shooting down or backwards
if (offX <= 0)
return;
// Determine where we wish to shoot the projectile to
int realX = winSize.width + (ball.contentSize.height/2);
float ratio = (float) offY/(float) offX;
int realY = (realX * ratio) + ball.position.y;
CGPoint realDest = ccp(realX, realY);
if(realX>=320)
realX = 320;
if(realY>=480)
realY = 480;
CGPoint realDest = ccp(realX, realY);
int good = goodBarrel.position.x;
int bad = badBarrel.position.x;
int destY = realDest.x;
if(destY<=good)
destY = good;
if(destY>=bad)
destY = bad;
realDest.x = destY+10;
// Determine the length of how far we're shooting
int offRealX = realX - ball.position.x;
int offRealY = realY - ball.position.y;
float length = sqrtf((offRealX*offRealX)+(offRealY*offRealY));
float velocity = 480/1; // 480pixels/1sec
float realMoveDuration = length/velocity;
// Move projectile to actual endpoint
[ball runAction:[CCSequence actions:
[CCMoveTo actionWithDuration:realMoveDuration position:realDest],
[CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)],
nil]];
}
ボールを遠くの場所に投げる効果を与えるためにボールが減少する。グッドバレルとバッドバレルはボールの反対側に置いた2本のバレルで、同じボールを入れます。私が取り組むことができる機能や方法はありますか?
この記事を見て、[紙の投げ方のベストな方法](http://www.cocos2d-iphone.org/forum/topic/21966#post-122109)をご覧ください。 – ccscanf