Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 同一类的多个对象仅引用其中一个对象_Ios_Objective C_Class_Cocos2d Iphone_Spritebuilder - Fatal编程技术网

Ios 同一类的多个对象仅引用其中一个对象

Ios 同一类的多个对象仅引用其中一个对象,ios,objective-c,class,cocos2d-iphone,spritebuilder,Ios,Objective C,Class,Cocos2d Iphone,Spritebuilder,我正在使用SpriteBuilder为游戏设计关卡。在游戏中,我有一个方块对象,当被刷卡时会移动。但是,如果级别中有多个对象,则每个对象仅引用最后添加的对象。它们都被初始化为唯一的对象,但当我滑动时,它们不会移动。唯一能正常工作的是添加到标高的最后一个 这里有刷卡手势 - (void)didLoadFromCCB { // Listen for swipe gestures to the right and left UISwipeGestureRecognizer * swipeRight=

我正在使用SpriteBuilder为游戏设计关卡。在游戏中,我有一个方块对象,当被刷卡时会移动。但是,如果级别中有多个对象,则每个对象仅引用最后添加的对象。它们都被初始化为唯一的对象,但当我滑动时,它们不会移动。唯一能正常工作的是添加到标高的最后一个

这里有刷卡手势

- (void)didLoadFromCCB {
// Listen for swipe gestures to the right and left
UISwipeGestureRecognizer * swipeRight= [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeRight)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[[[CCDirector sharedDirector] view] addGestureRecognizer:swipeRight];

UISwipeGestureRecognizer * swipeLeft= [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeLeft)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[[[CCDirector sharedDirector] view] addGestureRecognizer:swipeLeft];
}
下面是一种刷卡方法,它将错误的对象记录为self。我还有一个触摸开始的方法,记录正确的对象

- (void)swipeRight {

// Only move the object if it is being touched while swiping
CCLOG(@" Swipe right %@", self);
if (self.touched) {
    // Move the object off the screen to the right
    float width = [self parent].contentSizeInPoints.width;
    [self swipeOffScreen:ccp(self.position.x + width, self.position.y)];
}
}

我没有使用swipeRight方法,而是将代码移动到TouchEnd方法,并在touchMoved中将self.touch设置为true。我认为问题在于UIKit滑动包装器和cocos2dtouch方法之间的差异