gpt4 book ai didi

ios - Cocos2d v3.0 - 使用带动画的物理编辑器

转载 作者:行者123 更新时间:2023-11-29 12:47:23 27 4
gpt4 key购买 nike

我正在尝试使用物理编辑器为我的动画 Sprite 创建自定义物理。我正在按照 https://www.codeandweb.com/blog/2014/04/09/using-physicseditor-with-cocos2d-v3 中的指南进行操作, 但它没有显示如何处理动画。

下面是我的动画代码:

//adding the png with all the sprites(run)
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"run-hd.plist"];
CCSpriteBatchNode *runSheet = [CCSpriteBatchNode batchNodeWithFile:@"run-hd.png"];
[self addChild:runSheet];

//The sprite animation(run)
NSMutableArray *runAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 4; ++i)
{
[runAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Run%d-HDN.png", i]]];
}
CCAnimation *runAnim = [CCAnimation animationWithSpriteFrames:runAnimFrames delay:0.1f]; //Speed in which the frames will go at

//Adding png to sprite
_character = [CCSprite spriteWithImageNamed:@"Run1-HDN.png"];
_character.position = ccp(100,80);

//Repeating the sprite animation
CCActionAnimate *runAnimationAction = [CCActionAnimate actionWithAnimation:runAnim];
CCActionRepeatForever *runRepeatingAnimation = [CCActionRepeatForever actionWithAction:runAnimationAction];

//Animation continuously repeating
[_character runAction:runRepeatingAnimation];

//Adding the Sprite to the Scene
_character.physicsBody = [CCPhysicsBody bodyWithRect:(CGRect){CGPointZero, _character.contentSize} cornerRadius:0];
_character.physicsBody.collisionGroup = @"playerGroup";
_character.physicsBody.collisionType = @"playerCollision";
_character.scale = 2;
[_physicsWorld addChild:_character];

我在物理编辑器中使用自定义物理体创建了 .plist,有没有办法将它添加到我的代码中?还是有另一种方法来完成这项工作?谢谢!

最佳答案

我想通了。以防万一有人需要知道,这就是我所做的。首先,我需要添加在此处找到的 GCCShapeCache 类 https://github.com/CodeAndWeb/PhysicsEditor-Cocos2D-V3/tree/master/PhysicsEditor-Cocos2D-V3/Classes到我的项目。然后我添加了

#import "GCCShapeCache.h" 

添加到我的 HelloWorldScene.m 类,并将在物理编辑器中创建的 .plist 文件添加到我的项目中。然后我添加了

[[GCCShapeCache sharedShapeCache] addShapesWithFile:@"run.plist"];
[[GCCShapeCache sharedShapeCache] setBodyWithName:@"Run1-HDN" onNode:_character];

我的自定义形状已添加到我的项目中。

关于ios - Cocos2d v3.0 - 使用带动画的物理编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23301328/

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