开发者

iOS Cocos2d Sprite movement problem

开发者 https://www.devze.com 2023-03-21 17:19 出处:网络
int realX = winSize.width + (projectile.contentSize.width/2); float ratio = (float) offY / (float) offX;
int realX = winSize.width + (projectile.contentSize.width/2);
float ratio = (float) offY / (float) offX;
int realY = (realX * ratio) + projectile.position.y;
CGPoint realDest = ccp(realX, realY);
[_projectiles addObject:projectile];
projectile.tag = 2;


[projectile runAction:[CCSequence actions:
                       [CCMoveTo actionWithDuration:realMoveDuration position:realDest],
                       [CCCallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)],
                       nil]];

In this simple app, I am trying to make a projectile flying from the middle of the screen to wherever the user touches, and beyond, to the edge of the screen. For whatever reason, the projectile will only fly to destinations with positive x coordinates, no matter when the user presses. If you imagine an x y plane, with the center of the screen being origin, the projectile will only fly to places on in the quadrants to the right of origin. If the user touches a point on the l开发者_运维技巧eft two, the projectile flies in the opposite direction, on the same slope as the ratio of the touch to origin. .... .........? Any ideas, thanks in advance


You must consider the signs of the X and Y coordinates when you are calculating the ratio. That's the origin of your problem.

iOS Cocos2d Sprite movement problem

0

精彩评论

暂无评论...
验证码 换一张
取 消