1

[解决了]

我从 cocos2d+chipmunk 模板中复制了花栗鼠文件夹结构并构建好了。

  • “src”文件夹的类/Chipmunk/include/src
  • “包含”文件夹的类/Chipmunk/chipmunk

感谢 Beta 提供的帮助。

:::::

我下载了花栗鼠 5.3.1 并尝试了一个简单的例子,但我收到了这个编译错误:

Undefined symbols:
  "_cpSpaceStep", referenced from:
      -[ChipmunkTestViewController delta:] in ChipmunkTestViewController.o
  "_cpBodyNew", referenced from:
      -[ChipmunkTestViewController configurarChipmunk] in ChipmunkTestViewController.o
  "_cpSpaceAddShape", referenced from:
      -[ChipmunkTestViewController configurarChipmunk] in ChipmunkTestViewController.o
  "_cpSpaceAddBody", referenced from:
      -[ChipmunkTestViewController configurarChipmunk] in ChipmunkTestViewController.o
  "_cpSpaceHashEach", referenced from:
      -[ChipmunkTestViewController delta:] in ChipmunkTestViewController.o
  "_cpInitChipmunk", referenced from:
      -[ChipmunkTestViewController configurarChipmunk] in ChipmunkTestViewController.o
  "_cpCircleShapeNew", referenced from:
      -[ChipmunkTestViewController configurarChipmunk] in ChipmunkTestViewController.o
  "_cpSpaceNew", referenced from:
      -[ChipmunkTestViewController configurarChipmunk] in ChipmunkTestViewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

我不确定是否要正确添加 Chipmunk 库,我必须包括哪些来自 chipmunk .tgz 的来源?

这是代码:

ChipmunkTestViewController.h

#import <UIKit/UIKit.h>
#import "chipmunk.h"


@interface ChipmunkTestViewController : UIViewController {
    UIImageView *barra;
    UIImageView *esfera;

    cpSpace *space;
}

- (void) configurarChipmunk;
- (void) delta:(NSTimer *)timer;
void updateShape(void *ptr, void *unused);

@end

ChipmunkTestViewController.m

#import "ChipmunkTestViewController.h"

@implementation ChipmunkTestViewController


- (void) configurarChipmunk {
    cpInitChipmunk(); // Init Chipmunk engine

    space = cpSpaceNew(); // Create new Space
    space->gravity = cpv(0, -100); // Direcction and magnitude of gravity in Space

    [NSTimer scheduledTimerWithTimeInterval:1.0f/60.0f target:self selector:@selector(delta:) userInfo:nil repeats:YES];    // NSTimer for animations

    // Create esfera Body
    cpBody *esferaBody = cpBodyNew(50.0f, INFINITY); 
    esferaBody->p = cpv(160,250);
    // Create esfera Shape
    cpShape *esferaShape = cpCircleShapeNew(esferaBody, 15.0f, cpvzero);
    esferaShape->e = 0.5f; // Elasticity
    esferaShape->u = 0.8f; // Friction
    esferaShape->data = esfera; // UIImageView association
    esferaShape->collision_type = 1;

    cpSpaceAddBody(space, esferaBody);
    cpSpaceAddShape(space, esferaShape);

}

- (void) delta:(NSTimer *)timer {
    cpSpaceStep(space, 1.0f/60.0f);     // Refresh Space info
    cpSpaceHashEach(space->activeShapes, &updateShape, nil);     // Refresh Shapes info
}

void updateShape(void *ptr, void *unused) {
    cpShape *shape = (cpShape*)ptr;
    if (shape == nil || shape->body == nil || shape->data == nil) {
        NSLog(@"Invalid Shape...");
        return;
    }
    // Refresh Shape position
    if ([(UIView*)shape->data isKindOfClass:[UIView class]]) {
        [(UIView*)shape->data setCenter:CGPointMake(shape->body->p.x, 480 - shape->body->p.y)];
    } else {
        NSLog(@"Shape updated outside updateShape function...");
    }

}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    barra = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"barra.png"]];
    barra.center = CGPointMake(160, 350);
    esfera = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"esfera.png"]];
    esfera.center = CGPointMake(160, 230);

    [self.view addSubview:barra];
    [self.view addSubview:esfera];

    [self.view setBackgroundColor:[UIColor whiteColor]];

    [self configurarChipmunk];
}

...

@end
4

4 回答 4

4

您应该使用 macosx/ 目录中的 iphonestatic.command 脚本来构建静态库并像 README 中所说的那样为您复制标题。然后您所要做的就是将该文件夹放入您的项目中。

如果您只是将源代码复制到您的项目中,那么您几乎肯定会遗漏几个非常重要的优化标志。不要这样做!

于 2010-08-19T13:20:56.937 回答
0

我从 cocos2d+chipmunk 模板中复制了花栗鼠文件夹结构并构建好了。

* Classes/Chipmunk/include/src for 'src' folder
* Classes/Chipmunk/chipmunk for 'include' folder
于 2010-08-20T08:10:49.017 回答
0

这几天我有同样的问题,我这样做了:

1.- 转到项目 --> 添加到项目并找到 cocos2d-iphone-0.99.5 文件,然后在该目录中我添加了外部目录(包含花栗鼠文件)。确保选中将项目复制到目标组的文件夹(如果需要)旁边的复选框,然后单击添加按钮。

2.-我按照这个教程: http: //monoclestudios.com/cocos2d_whitepaper.html(页面中间是所有需要添加花栗鼠的信息)

3.- 将#include "constraints/util.h" 声明更改为:"#include util.h"

我认为已经完成了。

于 2011-04-25T11:28:48.180 回答
0

如果您使用 CocoaPods:

  1. 在 xCode 中单击您的Pods项目
  2. 选择花栗鼠物理目标
  3. 搜索路径中将始终搜索用户路径设置为
  4. 标题搜索路径集中

"${PODS_ROOT}/Headers/Private/chipmunk-physics" 到递归

"${PODS_ROOT}/Headers/Public/chipmunk-physics" 到递归

xcode 截图

希望它可以帮助某人

于 2015-12-02T08:55:07.850 回答