gpt4 book ai didi

iphone - 达到抛射运动的特定坐标?

转载 作者:行者123 更新时间:2023-12-03 20:07:57 24 4
gpt4 key购买 nike

因为我想以转换运动的方式制作图像动画,我的代码如下,但它没有到达目标并给出弹丸动画,请问有什么帮助吗?

-(void)timeLine
{

dTime += 0.1;


.................


double s_x = inVel * cos(angle1) ; // the X speed
double s_y = inVel * sin(angle1) ; // the Y speed


NSLog(@"sx = %i",s_x);

NSLog(@"sy = %i",s_y);


x = oX + (s_x * dTime);
y = oY + ( ( s_y * dTime) - (0.5 * 9.8 * dTime * dTime));

NSLog(@"x = %i",x);

NSLog(@"y = %i",y);

imageViewForAnimation.x += x;
imageViewForAnimation.y -= y;
}

最佳答案

imageViewForAnimation.x += x;
imageViewForAnimation.y -= y;

这些台词对我来说似乎不太正确。您每次计算的是实际的 x 和 y,而不是自上次以来移动的差值。我也不确定为什么要添加一个和减去一个,但这不是重点。基本上,尝试将行更改为

imageViewForAnimation.x = x;
imageViewForAnimation.y = y;

此外,您正在一遍又一遍地进行一些计算,而这些计算只需要完成一次。 v_x == s_x (或者应该在浮点误差内)以及 v_y == s_y。您只需预先计算一次 v_x 和 V_y,而不是每次更新坐标时都计算它们。

关于iphone - 达到抛射运动的特定坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7550815/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com