大家好我希望有人可以告诉我如何减少从阵列中添加的精灵之间的间距,当它们均匀间隔和居中时,我需要减小精灵之间的宽度
整个代码块就足以测试间距
了int images = 5
for(int i = 0; i < images; ++i)
{
///load same ammount of spriteimages as images
SKSpriteNode *sprite =
[SKSpriteNode spriteNodeWithImageNamed:@"Null.jpg"];
sprite.name = @"sprite.name =Sprite%d",[NSString stringWithFormat:@"%i",i];
NSLog(@"***sprite.name %@",[NSString stringWithFormat:@"%i",i]);
///spriteSpacing
float offsetFraction = ((float)(i + 1)) / (images + 1);
float widthOfScreen =self.frame.size.width;
sprite.position = CGPointMake(widthOfScreen * offsetFraction,self.frame.size.height/2 +200);
[self addChild:sprite];
}
答案 0 :(得分:0)
试试看看会发生什么
float widthOfScreen = self.frame.size.width + 100.0;
答案 1 :(得分:0)
最后我做了这个
float padding = 100.0f;
int blockWidth = [SKSpriteNode spriteNodeWithImageNamed:@"Null.jpg"].size.width;
float xOffset = (self.frame.size.width - (blockWidth * images + padding * (images-1))) / 2;
//float xOffset = (self.frame.size.width - (blockWidth * numberOfBlocks + padding * (numberOfBlocks-1))) / 2;
float StartPoint = xOffset+blockWidth/2;
for(int i = 0; i < images; ++i)
{
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"Null.jpg"];
///set start point of 1st sprite to load
if (i>0&&i<images)
{
StartPoint = StartPoint+ blockWidth+padding;
}
//increment sprite position
else if (i==images)
{
StartPoint = StartPoint+ blockWidth;
}
sprite.position = CGPointMake(StartPoint, self.frame.size.height * 0.8f);
[self addChild:sprite];
}