0
我可能已经开始太久了,根本看不到逻辑问题。我正在改变平底锅手势的背景图像。通过背景和循环的图像名称数组左右循环。数组索引中的逻辑问题
滑动右(增加)工作正常,它循环回到我的数组的开始。 向左滑动即可(减少在第一对象停止在我的数组(objectIndex:0)
NSLog(@"_imageBackgroundIndex Before:%d",_imageBackgroundIndex);
if ([_panDirection isEqual:@"Right"])
{
_imageBackgroundIndex = _imageBackgroundIndex + 1;
}
if ([_panDirection isEqual:@"Left"])
{
_imageBackgroundIndex = _imageBackgroundIndex - 1;
}
NSLog(@"_imageBackgroundIndex After:%d",_imageBackgroundIndex);
if (_imageBackgroundIndex > ([_backgroundImages count] - 1))
{
_imageBackgroundIndex = 0;
}
if (_imageBackgroundIndex < 0)
{
_imageBackgroundIndex = ([_backgroundImages count] - 1);
}
[[self childNodeWithName:kBackgroundName] runAction:
[SKAction setTexture:
[SKTexture textureWithImageNamed:
[_backgroundImages objectAtIndex:_imageBackgroundIndex]]]];
任何人看到这个问题