1

[解決済み]

cocos2d+chipmunk テンプレートからシマリスのフォルダ構成をコピーしてビルドOK。

  • 「src」フォルダーの Classes/Chipmunk/include/src
  • 「インクルード」フォルダーのクラス/シマリス/シマリス

助けようとしてくれた 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 テンプレートからシマリスのフォルダ構成をコピーしてビルドOK。

* 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. 検索パスで、常にユーザーパスを検索するをYESに設定します
  4. ヘッダー検索パスセット内

「${PODS_ROOT}/Headers/Private/chipmunk-physics」を再帰的に、

「${PODS_ROOT}/Headers/Public/chipmunk-physics」を再帰的に

xcodeのスクリーンショット

それが誰かを助けることを願っています

于 2015-12-02T08:55:07.850 に答える