Created
May 2, 2021 00:32
-
-
Save KinoAR/ba335c1c8ffdd9441718605b8b19cc90 to your computer and use it in GitHub Desktop.
Example Function for getting the Screen Position. This is directly from the Flixel Code Base.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Call this function to figure out the on-screen position of the object. | |
* | |
* @param Point Takes a `FlxPoint` object and assigns the post-scrolled X and Y values of this object to it. | |
* @param Camera Specify which game camera you want. | |
* If `null`, it will just grab the first global camera. | |
* @return The Point you passed in, or a new Point if you didn't pass one, | |
* containing the screen X and Y position of this object. | |
*/ | |
public function getScreenPosition(?point:FlxPoint, ?Camera:FlxCamera):FlxPoint | |
{ | |
if (point == null) | |
point = FlxPoint.get(); | |
if (Camera == null) | |
Camera = FlxG.camera; | |
point.set(x, y); | |
if (pixelPerfectPosition) | |
point.floor(); | |
return point.subtract(Camera.scroll.x * scrollFactor.x, Camera.scroll.y * scrollFactor.y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment