Closed Mmarzex closed 11 years ago
UI elements are by default positioned by a percent of screen size. Either you can set the posPct.x/y
between 0 and 1, or set posAsPct
to false and then set the pos.x/y
like you would with normal entities. Even better, do this all in the spawn settings:
if(ig.input.pressed('popup')){
this.someEl = ig.game.spawnEntity(ig.UITextBox, 100, 100, {
posAsPct: false,
text: 'Hello!!!!!'
});
}
Alright that makes sense, thanks for the quick response. All though I have one more question, if I were to add in that code to change the font would it be something like
this.someEl = ig.game.spawnEntity(ig.UITextBox, 100, 100, {
font: _c.FONT.CHAT_NAME,
posAsPct: false,
text: 'Hello!!!!!'
});
Or do I need to make a new font object? I'm using the jumpnrun demo from the repo so that font.chat_name is defined in the config-user.
Np. Font names are just paths to the font image. For actual fonts, check out https://github.com/collinhover/impactplusplus/blob/master/lib/plusplus/core/font.js#L282.
I got that, but I'm still not understanding how I would set a new font for my element? I set the font property as font: new ig.Font('media/font_04b03_black_8.png') and it still shows as the default in the textbox, am I doing something wrong still?
Ah I see, the issue is that you're using a UITextBox, not a UIText, and the UITextBox extends UITextBubble which extends UIOverlay. The overlay creates a UIText using the textSettings
property. So what you need is:
if(ig.input.pressed('popup')){
this.someEl = ig.game.spawnEntity(ig.UITextBox, 100, 100, {
posAsPct: false,
text: 'Hello!!!!!',
textSettings: {
font: ig.Font.FONTS.CHAT
}
});
}
Hi,
I'm a little unclear on how you move an UIElement, so here is my code
if(ig.input.pressed('popup')){ this.someEl = ig.game.spawnEntity(ig.UITextBox, 0, 0, {posPct: {x: 0, y: 0}, text: 'Hello!!!!!'}); this.someEl.moveToPosition({x: 100, y: 100}); }
is that the proper way to do that or am I missing a concept here because no matter what it always places it in the top left corner of the game window.