Skip to content

Instantly share code, notes, and snippets.

@KinoAR
Created May 2, 2021 00:32
Show Gist options
  • Save KinoAR/ba335c1c8ffdd9441718605b8b19cc90 to your computer and use it in GitHub Desktop.
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.
/**
* 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