IOS Game general screens are horizontal, so what happens when the screen is up. The cup has occurred and the coordinates have been problematic.
When the horizontal screen is the coordinates of the origin of the lower left corner (below the game template), at this point the size is 1024*768, and this size is the same size as the ipad Air, why is this size (maybe Apple wants us to have an ipad to play, not to hold the phone). When you use a different size device (like the iphone), the size of the scene doesn't change, what does that mean? That is, when you create a 100*100 square in the scene, it appears to be a rectangle on the screen.
OK, then come to our point-what happens when the screen is up. OK, I add the following code to the Gamescene class
This function can output the coordinates of the touch point in the screen.
I touch the lower left corner, the upper left corner, the lower right corner, the upper right corner (I use 5s simulator) output coordinates are as follows
Did you find it? The leftmost coordinates are not from 0, and the height is not 1024 of the imagination, what happened? We can see that the width of the coordinates starts from 297 to 727, and the height is from 0 to 768. For the high we can easily understand that is originally horizontal screen when the high tensile to the vertical screen, which is easy to understand, in the game template is 768 points (similar concept), perhaps a point in the horizontal screen when a pixel, and the vertical screen when a point represents two pixels. So since the high is stretching, the width is to the point of compression, but our cruel discovery is not!! The width of the lower left corner x-coordinate is not starting at 0, but probably starting at 297. This is why, I once again validated the horizontal screen when the coordinates point
Lower left corner, upper left corner, lower right corner, upper right corner
We found the problem, the width of the coordinates from 0 to 1024 this is no problem, but the high coordinates are from 97 to 668. Why the hell is this? (I don't know ~~~~~~~~~~~)
To sum up: horizontal screen when the width corresponding to the height of the vertical screen, this is no problem. The height of the horizontal screen and the width of the vertical screen exceed the screen. Specifically why, perhaps, and design patterns, if the great God saw this article, and just know the problem, please enlighten me.
So how to solve the problem, that is, to change the width from 0 to 1024, and the height from 0 to 768. My approach is to enter another scene as soon as I enter the Gamescene and set the size of another scene to Self.size. Create a new class in the project, the class inherits from Skscene, the name is Playscene, and then the following code is written in Gamescnene
Then when you go into the gamescene and then turn to the Playscene, the playscene coordinates are from 0-1024, 0-768.