NSObject
いくつかのメンバー変数を含むサブクラスを作成したいと思います:
@interface PointMass : NSObject
{
CGPoint mCurPosition;
CGPoint mLastPosition;
CGPoint mAcceleration;
}
-(id) initWithPosition:(CGPoint*) pos;
#import "PointMass.h"
@implementation PointMass
-(id) initWithPosition:(CGPoint*)pos
{
mCurPosition = *pos;
mLastPosition = *pos;
mAcceleration = ccp(0,0);
return self;
}
@end
そして、cocos2d クラス内にそれらの束を保持する C スタイルの配列を作成したいと思います。
// mNumPoint declared in interface, I've set it to 100
PointMass *pointMassList;
pointMassList = malloc(sizeof(PointMass*) * mNumPointMass);
for (int = 0; i < mNumPointMass; i++)
{
CGPoint point = ccp(100,100);
PointMass *p = [[PointMass alloc] initWithPosition: &point];
pointMassList[i] = p;
}
しかし、私はエラーが発生します
Expected method to write array element not found on object of type 'PointMass *'
PointMass オブジェクトへのポインターを C 配列に格納したい場合、コンパイラーに PointMass オブジェクトについて詳しく伝える必要がありますか?
ここで何を達成しようとしているのかが明確でない場合は、基本的に、NSArray からポイントを常にアンパックする必要なく、iPhone でいくつかの粒子計算をいじろうとしています。
私がこれについて逆方向に行った場合は、修正していただきたいと思います.バニラCを書いてからしばらく経ちましたが、少し錆びています!