Я новичок в Cocos2d и, следовательно, не знаю большинства классов, а также функций.В моем приложении я хочу реализовать модуль, такой как касание и перетаскивание мяча в направлении ствола, который пропустит шарик и поместит шарик в ствол.Я могу передать мяч в направлении, но тогда он просто исчезнет с экрана, следуя координатам (xy).
- (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]];
}
Мне нужно сделать что-то вроде этого, чтобы получить представление о положении бочек и нахождении верха бочки, и поместить мяч в центр бочки, а также при перемещении мяча размермяча уменьшается, чтобы дать эффект броска мяча в отдаленное место.GoodBarrel и BadBarrel - это две бочки, которые я положил напротив мяча, чтобы положить их в одну.Есть ли какая-либо функция или метод, над которым я могу работать?