我需要将我的代码转换为 ARC。我有一个用于绘制路径的 CCArray。我填充来自不同类的 CCArray 值的对象。
问题是转换为 ARC 后,CCArray 总是返回null
我看不出我做错了什么。
瓢虫.h
@interface Ladybug : CCSprite <CCTargetedTouchDelegate>{
CCArray *linePathPosition;
}
@property (nonatomic, strong) CCArray *linePathPosition;
@end
瓢虫.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 的正确方法是什么?