コードをARCに変換する必要がありました。パスを描画するために使用するCCArrayがあります。別のクラスのCCArray値のオブジェクトを入力します。
問題はARCに変換した後、CCArrayは常にnull
自分が間違っていることがわかりません。
てんとう虫.h
@interface Ladybug : CCSprite <CCTargetedTouchDelegate>{
CCArray *linePathPosition;
}
@property (nonatomic, strong) CCArray *linePathPosition;
@end
Ladybug.m
@synthesize linePathPosition;
-(id) init
{
if( (self=[super init] )) {
self.linePathPosition = [[CCArray alloc] init];
}
return self;
}
-(void) updatePosition:(CGPoint) position
{
[self.linePathPosition addObject:[NSValue valueWithCGPoint:position]];
NSLog(@"line path %@",linePathPosition);
}
-(void) breakMoveLadyBug
{
[self.linePathPosition removeAllObjects];
}
メインで.m
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
Ladybug *ladybug1 = (Ladybug *)[self getChildByTag:99];
CCMotionStreak* streak = (CCMotionStreak *)[self getChildByTag:999];
CGPoint touchLocation = [touch locationInView: [touch view]];
CGPoint curPosition = [[CCDirector sharedDirector] convertToGL:touchLocation];
if (ladybug1.isSelected) {
streak.position = curPosition;
[ladybug1 updatePosition:curPosition];
NSLog(@"Cur position %@",NSStringFromCGPoint(curPosition));
if (!ladybug1.isMoving) {
[ladybug1 startMoveLadyBug];
}
}
}
ログ:
Cur position {331, 110}
line path (null)
私は何が間違っているのですか?ARCでCCArrayを定義して初期化する適切な方法は何ですか?