如何在Cocos2d v3中设置CCTextField

car*_*lal 2 objective-c cocos2d-iphone xcode5

这是我到目前为止所得到的:

enterName = [CCTextField textFieldWithSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"Tile.png"]];
enterName.fontSize = 16.0f;
enterName.positionType = CCPositionTypeNormalized;
enterName.position = ccp(0.5f, 0.5f);
enterName.scale = 0.70f;
[self addChild:enterName z:5];
Run Code Online (Sandbox Code Playgroud)

基本上,它创建了一个几乎无法点击的微观文本字段.弹出CCTextField的唯一方法是"textFieldWithSpriteImage".

额外帮助:如何存储输入后输入的字符串.干杯.

car*_*lal 5

为了防止Cocos2d中的微观CCTextFields,请务必进行设置preferredSize.

这是防止微观文本字段的代码:

CCSprite *textSprite = [CCSprite spriteWithImageNamed:@"Tile.png"];
enterName = [CCTextField textFieldWithSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"Tile.png"]];
enterName.fontSize = 16.0f;
enterName.contentSize = CGSizeMake(100.0f, 50.0f);
enterName.preferredSize = textSprite.contentSize; // don't forget this !
enterName.positionType = CCPositionTypeNormalized;
enterName.position = ccp(0.5f, 0.5f);
[self addChild:enterName z:5];
Run Code Online (Sandbox Code Playgroud)