Skip to content

Instantly share code, notes, and snippets.

@adamlwgriffiths
Created January 7, 2015 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamlwgriffiths/517aaf5ba5abcb4b6f16 to your computer and use it in GitHub Desktop.
Save adamlwgriffiths/517aaf5ba5abcb4b6f16 to your computer and use it in GitHub Desktop.
EditBox placement error
var IOS_NamePlayer = cc.Scene.extend({
layer: null,
next_scene: null,
text_field: null,
placeholder: "Input text here",
ctor: function() {
this._super();
this.layer = cc.Layer.create();
this.addChild(this.layer);
var winsize = cc.director.getWinSize();
var ebox = cc.EditBox.create(cc.size(170, 50), cc.Scale9Sprite.create(res.edit_box), cc.Scale9Sprite.create(res.edit_box));
ebox.setPlaceHolder("Password");
ebox.setInputFlag(cc.EDITBOX_INPUT_FLAG_PASSWORD);
ebox.setPosition(cc.p(winsize.width/2,winsize.height/2));
ebox.setFontColor({"r": 50, "g": 50, "b": 50});
ebox.setDelegate(this);
this.layer.addChild(ebox,1);
/*
this.text_field = cc.EditBox.create(cc.size(200, 25), cc.Scale9Sprite.create(res.edit_box), cc.Scale9Sprite.create(res.edit_box), cc.Scale9Sprite.create(res.edit_box));
//this.text_field.setPlaceholderFontColor(cc.color(255, 0, 0));
this.text_field.setPlaceHolder("Player name");
//this.text_field.x = winsize.width / 2;
//this.text_field.y = winsize.height / 2;
this.text_field.setPosition(winsize.width / 2, winsize.height / 2);
this.text_field.setFontColor({"r": 255, "g": 255, "b": 255});
this.text_field.setDelegate(this);
//this.text_field.setFontColor(cc.color(255, 0, 0));
//this.text_field.setMaxLength(20);
//this.text_field.setAnchorPoint(cc.p(0,0));
//this.text_field.setFontSize(30);
this.text_field.init();
this.layer.addChild(this.text_field);
*/
/*
this.text_field = new ccui.TextField();
this.text_field.setTouchEnabled(true);
//this.text_field.fontName = "Marker Felt";
this.text_field.placeHolder = this.placeholder;
this.text_field.fontSize = 30;
this.text_field.setMaxLengthEnabled(true);
this.text_field.setMaxLength(20);
this.text_field.x = winsize.width / 2;
this.text_field.y = winsize.height / 2;
this.text_field.addEventListener(this.text_field_event, this);
this.layer.addChild(this.text_field);
*/
},
editBoxEditingDidBegin: function(editBox) {
cc.log("DidBegin !");
},
editBoxEditingDidEnd: function(editBox) {
cc.log("DidEnd !");
},
editBoxTextChanged: function(editBox, text) {
cc.log("TextChanged, text: " + text);
},
editBoxReturn: function(editBox) {
cc.log("was returned !");
//this.chatLabel.setString(this._getEditBoxName(editBox));
},
text_field_event: function(sender, type) {
switch (type) {
case ccui.TextField.EVENT_ATTACH_WITH_IME: {
cc.log("Activate");
//this.text_field.placeHolder = "";
} break;
case ccui.TextField.EVENT_DETACH_WITH_IME: {
cc.log("Deactivate");
//this.text_field.placeHolder = this.placeholder;
} break;
case ccui.TextField.EVENT_INSERT_TEXT: {
cc.log("Insert character");
cc.log(this.text_field.string);
} break;
case ccui.TextField.EVENT_DELETE_BACKWARD: {
cc.log("Delect character");
cc.log(this.text_field.string);
} break;
}
}
});
IOS_NamePlayer.create = function() {
return new IOS_NamePlayer();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment