[解决]
我从cocos2d + 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
答案 0 :(得分:4)
您应该使用macosx /目录中的iphonestatic.command脚本来构建静态库并为您复制标题,就像README所说的那样。然后,您只需将该文件夹放入项目中即可。
如果您只是将源代码复制到项目中,几乎肯定会遗漏几个非常重要的优化标记。不要这样做!
答案 1 :(得分:0)
我从cocos2d + chipmunk模板中复制了chipmunk文件夹结构并构建好。
* Classes/Chipmunk/include/src for 'src' folder
* Classes/Chipmunk/chipmunk for 'include' folder
答案 2 :(得分:0)
这几天我有同样的问题,我这样做了:
1.-转到项目 - &gt;添加到项目并找到cocos2d-iphone-0.99.5文件,然后在该目录中我添加了外部目录(包含chipmunk文件)。确保在将项目复制到目标组的文件夹(如果需要)旁边的框中有复选标记,然后单击添加按钮。
2.-我遵循本教程:http://monoclestudios.com/cocos2d_whitepaper.html(在页面中间是需要添加花栗鼠的所有信息)
3.-将#include“constraints / util.h”声明更改为:“#include util.h”
我认为已经完成了。
答案 3 :(得分:0)