gpt4 book ai didi

ios - 也围绕自身中心旋转物体吗?

转载 作者:行者123 更新时间:2023-11-29 03:35:26 25 4
gpt4 key购买 nike

star.rotation += star.speed;
float angleRadian = star.rotation * PI_DIV_180;
star.position = ccp(windowSize.width/2 + (star.radius * sinf(angleRadian)), windowSize.height/2 + (star.radius * cosf(angleRadian)));

上面是在调用每一帧时沿窗口中心点旋转 star Sprite 。 anchor 是星形的中心。我怎样才能让星星也沿着自身中心旋转?

最佳答案

您想要相互绕轨道运行并绕自己的轴自转/自转的物体吗?是这样的吗?

旋转测试.h

@interface RotationTest : CCLayer
{
CCSprite *star;
CCSprite *planet;
CCSprite *satellite;

float dist_star_planet;
float dist_planet_satellite;

float relative_angle_star_planet;
float relative_angle_planet_satellite;
}

@end

旋转测试.m

#import "RotationTest.h"

@implementation RotationTest

-(id) init
{
if( (self=[super init]))
{
CGSize s = [[CCDirector sharedDirector] winSize];

star = [CCSprite spriteWithFile:@"Icon.png"];
planet = [CCSprite spriteWithFile:@"Icon.png"];
satellite = [CCSprite spriteWithFile:@"Icon.png"];

[self addChild: star];
[self addChild:planet];
[self addChild:satellite];

star.position = ccp(s.width / 2.0f, s.height / 2.0f);
planet.position = ccpAdd(star.position, ccp(100.0f, 0.0f));
satellite.position = ccpAdd(planet.position, ccp(50.0f, 0.0f));

star.scale = 0.5f;
planet.scale = 0.35f;
satellite.scale = 0.2f;

dist_star_planet = ccpDistance(planet.position, star.position);
dist_planet_satellite = ccpDistance(satellite.position, planet.position);

relative_angle_star_planet = 0.0f;
relative_angle_planet_satellite = 0.0f;

[self scheduleUpdate];
}
return self;
}

-(void) update:(ccTime) dt
{
star.rotation += 1.0f; // degs
planet.rotation -= 1.0f;
satellite.rotation += 2.0f;

relative_angle_star_planet += 0.01f; // rads
relative_angle_planet_satellite -= 0.01f;

planet.position = ccpAdd(star.position, ccp(dist_star_planet * sinf(relative_angle_star_planet), dist_star_planet * cosf(relative_angle_star_planet)));
satellite.position = ccpAdd(planet.position, ccp(dist_planet_satellite * sinf(relative_angle_planet_satellite), dist_planet_satellite * cosf(relative_angle_planet_satellite)));
}

@end

关于ios - 也围绕自身中心旋转物体吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19244582/

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