-
Notifications
You must be signed in to change notification settings - Fork 2
tutorial.basic.2
Hi, welcome back to the second beginners tutorial to uiz!
Today weβll cover what βparentsβ are. It is quite important that you understand them properly since it is the way you will have to structure all of your ui.
Sometimes, we want to put one object into another. Why do we want to do this?
This might be because we have a window for example, with a few buttons inside of it. You want those buttons to be βconnectedβ to the window. This way when we drag the window around, the buttons that are "inside" the window are also dragged around.
Another example might be is that you have some sort of square, in which you want to put some health bars, stamina bars, etcβ¦. That square with the different bars could be snapped to the right side of your screen. When we change the size of our window, the square should move with it, but we also want our bars to move with it.
Thatβs where parenting comes in. It literally allows us to put one object inside another. The object which were putting in another object is called the βchildβ and the object weβre putting stuff in is called the βparentβ. A child can also be another parent for another object.
Does this still sound vague to you? On the parent documentation page is another good example and explanation of how parenting works. Please read the page before continuing this tutorial.
What we ABSOLUTELY CANNOT do, is making a child the parent of itβs own parent. This will cause a lot of issues. Bugs, loops, crashes, etc.
The things that parents do, is they dynamically influence their childrenβs data. For example, when the position of a parent moves 5 pixels to the left, the child will also move 5 pixels to the left. The parentβs size only has effect on itβs children in some cases, which weβll cover later.
Another thing to note is that βpositionsβ are added together. For example: a parent might be at position (100px, 150px). The specified position of the child is (100px, 25px). What will happen now is that the position of the parent stays (100px, 150px]) but the position of the child will add up and change to (200px, 175px).
If you would make the position of a child (0,0) it will always be placed inside the top-left corner of that parent.
It is very important that you understand how parenting works in order to properly use uiz.
Now letβs look at how we actually define our parents. Simple, we just call the uiz_setParent function. It takes 2 arguments: The object we want to give/set a parent (our new βchildβ) and the object we want to put our object in (our new βparentβ). So if we wanted put our βsquareβ inside an βcircleβ, we would do this by calling uiz_setParent(square, circle).
Now, remember the 4 important points from the last tutorial? "Creating, parenting, variables and fixing." Parenting is in here because it is gives the structure to your ui. You donβt always need to set a parent but more often that not you will need to set a parent.
Quick technical detail here: If you didnβt set a parent for your object, then the default parent for your object is obj_uiZ_controller. Which is an object from which only one exists and should exist. This object is created by using uiz_init().
Example:
Here we put a βsquareβ inside a βgradientsquareβ:
///Example 6:
//create event of a newly created object.
//initialize uiz
uiz_init()
//create our gradientsquare object
gradient=uiz_c(obj_uiZ_gradientsquare)
//our parent is the uiz controller object.
//setup some variables
uiz_position(gradient, 50,px, 50,px);
uiz_size(gradient, 200,px, 200,px);
//fix our square object.
uiz_fix(gradient)
//create our square object
square=uiz_c(obj_uiZ_square)
//set the parent
uiz_setParent(square,gradient)
//setup some variables
uiz_position(square, 25,px, 25,px);
uiz_size(square, 40,px, 50,px);
//fix our square object.
uiz_fix(square)
Which should look like:
IMAGE 6I hope this was somewhat clear. Later parenting will come back in advanced structures like grids, frameset etcβ¦.
In this tutorial you learned:
- how parenting works in abstract
- what a parent is
- what a child is
- how to assign parents in code
- that you should not create circular parent-child structures.
Until next tutorial! We will look at more different positioning types.
πTutorials
Basics 1: Basic positioning
Basics 2: Parenting system
Basics 3: Advanced positioning
Basics 4: Advanced sizing and set point
Basics 5: Canvas and containment
Basics 6: Alpha and depth
Basics 7: Using the manual and Animations
Basics 8: Object backgrounds
Basics 9: Grids
Basics 10: Framesets
Basics 11: Windows
Basics 12: Scroll bars
βοΈ Positioning
π Depth
π Structures
π Objects
obj_uiZ_3waybutton
obj_uiZ_button
obj_uiZ_checkbox
obj_uiZ_clock
obj_uiZ_colorbox
obj_uiZ_cover
obj_uiZ_drawdslist
obj_uiZ_dropdown
obj_uiZ_easybutton
obj_uiZ_frame
obj_uiZ_framescrollbar
obj_uiZ_functionbar
obj_uiZ_gradientsquare
obj_uiZ_gradientroundrect
obj_uiZ_gridlist
obj_uiZ_huesquare
obj_uiZ_loadingbar
obj_uiZ_loadingcircle
obj_uiZ_menubutton
obj_uiZ_mousemenu
obj_uiZ_radiobox
obj_uiZ_rotator
obj_uiZ_slider
obj_uiZ_scrollbar
obj_uiZ_slider_2col
obj_uiZ_slickslider
obj_uiZ_slideframe
obj_uiZ_sprbutton
obj_uiZ_spriteanimationbutton
obj_uiZ_spritecounter
obj_uiZ_stringbox
obj_uiZ_sliderstruct
obj_uiZ_surfacecanvas
obj_uiZ_sprite
obj_uiZ_square
obj_uiZ_squarebutton
obj_uiZ_swipicon
obj_uiZ_switch
obj_uiZ_tabslider
obj_uiZ_tabs
obj_uiZ_treelist
obj_uiZ_text
obj_uiZ_text_background
obj_uiZ_textarea
obj_uiZ_valuebox
π Strings
uiz_addChar
uiz_changechar
uiz_charCanHaveAddon
uiz_returnCharAddon
uiz_charIsNumber
uiz_charIsNumberOrText
uiz_getlines
uiz_gettext_contained
uiz_gettextlines_contained
uiz_getValidVariableName
uiz_isSpaceChar
uiz_lastStringChars
uiz_removeChar
uiz_replaceChars_
uiz_string_copy
uiz_string_digits
uiz_string_format
uiz_string_fromReal
uiz_string_real_getFracLength
uiz_string_real_getIntLength
uiz_string_repeat
uiz_string_replace
uiz_string_pos_at
uiz_stringUntilNewline