Center Me Please
Ok, everything is loaded but it's too big and doesn't fit our screen. let's fix that issue.
Video Transcript
00:00Now the next step that we want to do is we want to go to our image one now that we already have it
00:04And we could ask for its width and ask for its height so with that
00:08image one dot with
00:11Image one dot height so you know what I'm gonna even leave this right now with the hard-coded values
00:16And then maybe for you as homework if you choose to do it just
00:20abstract these values and instead of using hard-coded values make it a different value and the second homework exercise would be
00:28load two things and use the same event on complete and see if you could do that and if you can't
00:33Then shoot me a note and or let's talk about it on the Facebook
00:37And we could bring up a conversation about it and see who's the first one that could solve it all right
00:41So let's run this one more time just quickly and we'll see that when the application will finish loading
00:46We'll get the width and height now to keep the ratio, and we want to keep the ratio
00:50We want to make sure that it fits into our current stage width and height now our current stage width and height
00:56We could what we could do is we could say
01:00What we could do is first we could we want to ask to basically ask a question
01:04How do we make it smaller, but then it's going to fit the maximum size that we can inside of our screen
01:09Okay, so the best way to do that is first is to check. What is the biggest part and
01:14Do the ratios based on the biggest part so we know right now technically that the biggest part is the height but
01:22Programmatically we really didn't know that yet, so we could ask you a question all right
01:26We're going to ask a question if our height
01:30Is greater than our width
01:33We're going to do one thing if our height is not then we're going to do another thing whoopsie
01:41All right, so we have your the logic starting to sit in place, so if our height is bigger
01:48That means our image is really tall and we want to resize it based on our height of our stage
01:56Okay, so the easiest way to do that is we could go directly into our we want to actually
02:04We want to find what would be that ratio to find that ratio all we have to do
02:08We could take that image height, and we could ask the image height basically
02:15We could divide our stage height by our image height, so if our image, and let me just do that really really quick
02:21We're just going to trace the height. We're not even going to divide it. Okay, so we're going to trace your their image height
02:27And we're going to ask our stage that stage height
02:30Which we played with a little bit we played with this in earlier videos while in the other one in our else
02:36we're going to trace that with instead and
02:40Stage width and just to make sure that we know what if we're in we're just going to put here height
02:49And I'm going to put here with
02:51All right, so let's run this so again is going to load and when it finishes loading then only we're going to get that
03:02Information and then we're going to see okay our height is actually the biggest now our actually space that we have in our screen is
03:09400 pixels
03:11Well, we want to know is how much is the ratio between 400 in that number?
03:16So what we'd want to do is basically we want to just divide our stage height
03:21by our width
03:22By doing that we're going to get a value
03:24That's you know a percentage which will be a smaller value so we could take that smaller value and already automatically
03:30Just say that our image
03:32image one dot
03:35Scale X equals image one dot scale
03:40Y
03:41Equals that value now. Let's see what happens now the same thing we would do for
03:47In a case where the width would be but in the case of the width instead of that we'd be using our width as our
03:53First divider and our height as the second as sorry and a width of the image is the second one now if we run our application
04:00One more time we should get our image now smaller in a ratio that would actually fit into the screen
04:05Perfect, and it fits perfectly based on the ratio into the screen the last thing that we really want to have to do
04:11That we have left is let's say we want to just center it in the stage
04:14So now after we resize and it really doesn't matter it doesn't have to be in the if anymore now that we resized it
04:21We could go into our element and just ask basically based on on the stage basically want to take our image
04:27One dot X position and we want to change it based on the the leftover between our stage dot stage
04:36with minus
04:38image one dot with
04:43We want to divide that by two because we want to have the same space between the two sides and
04:48There we go and obviously if we wanted to we could have used tween max or something like that to actually
04:54load it in so for example, we could have faded the image in instead of just
04:59Just instead of just like putting it right in
