我想同时移动、动画和旋转对象
这是代码:
ball = [CCSprite spriteWithFile:@"Ball.png" rect:CGRectMake(0, 0, 52, 52)];
ball.position = ccp(300, 300);
ball.tag = 1;
[self addChild:ball z:-1];
// Create ball body
//b2BodyDef ballBodyDef;
ballBodyDef.type = b2_dynamicBody;
ballBodyDef.position.Set(100/PTM_RATIO, 300/PTM_RATIO);
ballBodyDef.userData = ball;
b2Body * ballBody = _world->CreateBody(&ballBodyDef);
// Create circle shape
b2CircleShape circle;
circle.m_radius = 20.0/PTM_RATIO;
// Create shape definition and add to body
b2FixtureDef ballShapeDef;
ballShapeDef.shape = &circle;
ballShapeDef.density = -2.5f;
ballShapeDef.friction = 0.01f;
ballShapeDef.restitution = 1.0f;
_ballFixture = ballBody->CreateFixture(&ballShapeDef);
b2Vec2 force = b2Vec2(5, 7);
ballBody->ApplyLinearImpulse(force, ballBodyDef.position);
我想要旋转、动画和移动球,但我很困惑,如何同时应用所有东西!?
Here is the code:
ball = [CCSprite spriteWithFile:@"Ball.png" rect:CGRectMake(0, 0, 52, 52)];
ball.position = ccp(300, 300);
ball.tag = 1;
[self addChild:ball z:-1];
// Create ball body
//b2BodyDef ballBodyDef;
ballBodyDef.type = b2_dynamicBody;
ballBodyDef.position.Set(100/PTM_RATIO, 300/PTM_RATIO);
ballBodyDef.userData = ball;
b2Body * ballBody = _world->CreateBody(&ballBodyDef);
// Create circle shape
b2CircleShape circle;
circle.m_radius = 20.0/PTM_RATIO;
// Create shape definition and add to body
b2FixtureDef ballShapeDef;
ballShapeDef.shape = &circle;
ballShapeDef.density = -2.5f;
ballShapeDef.friction = 0.01f;
ballShapeDef.restitution = 1.0f;
_ballFixture = ballBody->CreateFixture(&ballShapeDef);
b2Vec2 force = b2Vec2(5, 7);
ballBody->ApplyLinearImpulse(force, ballBodyDef.position);
I want to rotate,animate and move ball but i am confused,How to apply all things at the same time!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Spawn 动作同时进行多个动作。
id spawAction = [CCSpawn 动作:moveAction、rotateAction、nil];
[aSprite runAction:spawAction];
Using Spawn action to play many action at the same time.
id spawAction = [CCSpawn actions:moveAction, rotateAction, nil];
[aSprite runAction:spawAction];
例如,如何将box2d位置和旋转应用于CCNode,
顺便说一下,CCBox2D对cocos2d和盒子2d。
For example, how to apply box2d position and rotation to CCNode,
By the way, CCBox2D is helpful with cocos2d and Box2d.