gpt4 book ai didi

iOS,使用cocos2d-ObjC设置场景帧大小

转载 作者:行者123 更新时间:2023-11-28 23:30:13 25 4
gpt4 key购买 nike

enter image description here

我是 cocos2d 的初学者,我需要初始化场景框架,使其小于设备屏幕尺寸,如中间固定图片所示。此外,场景必须按图片所示缩放。我尝试过如下操作,但没有成功。

- (void)drawBackground
{
NSArray *assetPathParts = [self.dataProvider.backgroundValue componentsSeparatedByString:@"/"];
self.background = [CCSprite spriteWithImageNamed:assetPathParts.lastObject];
self.background.anchorPoint = ccp(0,0);
self.background.scale = 2;
self.background.scaleType = CCScaleTypeScaled;
[self addChild:self.background];
}

如何修复它?

最佳答案

调整屏幕大小的两种方法。

方法1:

CGSize wSize = [[CCDirector sharedDirector] winSize];

CCSprite *background = [CCSprite spriteWithFile:@"Kundapura.png"];
background.position = ccp(wSize.width*0.5f, wSize.height*0.5f);
[self addChild:background];
background.scaleX = wSize.width/background.contentSize.width ;
background.scaleY = wSize.height/background.contentSize.height ;

方法2:

CGSize wSize = [[CCDirector sharedDirector] winSize];

CCSprite *image = [CCSprite spriteWithFile:@"Kundapura.png"];
CCSprite *background = [CCSprite spriteWithTexture: image.texture rect:CGRectMake(0, 0, wSize.width, wSize.height)];

background.position = ccp(wSize.width*0.5f, wSize.height*0.5f);
[self addChild:background];

这适合您的背景到 iPhone 设备的尺寸。使用 runAction 来根据您的需求进行扩展。

关于iOS,使用cocos2d-ObjC设置场景帧大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56859786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com