This project is read-only.

CCTextFieldTTF not showing keyboard

Topics: Controllers and Device Hardware
Oct 21, 2013 at 4:24 AM

i am trying to capture the player name but i can't only using CCTextFieldTTF.

first issue:
TouchEnabled property is not working well. I have set it on my layer constructor but only after layer is shown on the screen and i change the value (debugger) it uses the "false" value.
This is important because when value is "true", i can't get touch events.

second issue:
Edit method: Even using AutoEdit value on "true", the Edit method doesn't show the keyboard, i have checked the CCTextFieldTTF source code, and i have forced the keyborad to show on the screen.
protected void InitTextField()
            CCSize winSize = CCDirector.SharedDirector.WinSize;
            CCSpriteBatchNode selectAtlas = new CCSpriteBatchNode("images/select.png");

            CCSprite textSprite = new CCSprite("selectEnterName.png");
            textSprite.Position = new CCPoint(winSize.Width / 2, 563);

            textField = new CCTextFieldTTF("<Player Name>", "Impact", 32, new CCSize(675, 92), CCTextAlignment.Center);
            textField.Position = textSprite.Position;
            textField.AutoEdit = true;
            textField.KeyboardEnabled = true;
            textField.Color = CCColor3B.Black;


            textField.TouchEnabled = false;//to allow touch event on this layer (Now Working Here!!?)

public override void TouchesBegan(List<CCTouch> touches)
            CCTouch touch = touches[0];

            if (textField.BoundingBox.ContainsPoint(touch.Location))
                textField.Edit("CCTextFieldTTF test", "Enter text"); //Not Working, next line force the keyboard on the screen!
                Guide.BeginShowKeyboardInput(Microsoft.Xna.Framework.PlayerIndex.One, "Player Name", "", textField.Text, InputHandler, null);

Oct 29, 2013 at 5:12 PM
Edited Oct 29, 2013 at 5:12 PM
First Issue - only set the TouchEnabled in OnEnter. If you do it in the ctor, then CCLayer.init() will override it.

You don't need the touch delegate to send you touches until your layer is actually visible.
Oct 29, 2013 at 5:17 PM
keyboard display bug:

Please log bugs on github if you can. Thanks!
Oct 29, 2013 at 8:33 PM
Make sure you have a GamerServicesComponent added to your CCApplication component. This will enable the gamer services such as the keyboard input. Without this component, the keyboard will not work.

On Windows XNA, though, you may find that GamerServicesComponent will require the Xbox Live keys ... so if you get some weird errors that make no sense, then it's like the missing XDK authorization keys.