@resserone13 said:
@Robert_Tompkins can you explain to me what’s going on here. I figure you account for something by subtracting and multiplying. Also what is the center[0] doing?
stopSelectorButton.x = (stormView.center[0] - (stopSelectorButton.width * 0.5))
And here.
add_room_button.center = ( (add_room_view.width / 2), (add_room_view.height / 2) )
Alright, so first things first..
stopSelectorButton is essentially an object that will be placed on screen.
We need to describe what it looks like, and where it will be.
The size consists of a width and a height (in pixels?)
So size can be defined as ( (object.width = 100), (object.height = 50) )
To answer your questions:
stopSelectorButton.x = (stormView.center[0] - (stopSelectorButton.width * 0.5))
Here we are defining where to place the LEFT side of the button.
The StormView.center parameter contains an x and a y coordinate describing where it’s center point is located.
Printing it produces something like this: (100.00, 200.00).
This is a list of 2 items:
’index 0’ or ‘[0]’ contains 100.00 This is the x coordinate of its center
‘Index 1’ or ‘[1]’ contains 200.00 This is the y coordinate of its center
So by saying: stormView.center[0], we are specifying The value of its x coordinate center point, 100.00
If we place the button’s left side at: stormView.center[0]
Our button would start at the center of stormView, but would extend 100 pixels to the right since the button is 100 pixels wide.
To make up for this, I took half of the button’s width: stopSelectorButton.width * 0.5
And subtracted that from the center of the view’s x coordinate to shift it left by half of its width.
The easier way is the second one you pointed out.
By placing the button using its center coordinate, we could place it in the center of the view like this:
add_room_button.center = ( (add_room_view.width / 2), (add_room_view.height / 2) )
or
add_room_button.center = ( (add_room_view.center[0]), (add_room_view.center[1]) )
or
add_room_button.center = add_room_view.center
Since our button’s center parameter must be a set of 2 values: x and y coordinates any should do the trick.
Long story short, I am accounting for the width and height of the button, which is only necessary if you are placing it using its x and y corner coordinates (top left).
Because the button will extend Right past the x coordinate by its width, and Down past its y coordinate by its height.