generated from yordan-kanchelov/pixi-typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert from osupixels to screen pixels
- Loading branch information
Showing
3 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as PIXI from "pixi.js"; | ||
import {Origin} from "./Beatmap/Data/Sections/Events/Storyboard/Origin"; | ||
import {Screen} from "../Screens/Screen"; | ||
|
||
export class StoryBoardUtil { | ||
public static ConvertOsuPixels(position: PIXI.PointData, origin: Origin, wideScreen: boolean) { | ||
let screenWidth = Screen.getScreenWidth(); | ||
let screenHeight = Screen.getScreenHeight(); | ||
let osuWidth43 = 640; | ||
let osuWidth = wideScreen ? 854 : osuWidth43; | ||
let osuHeight = 480; | ||
let widthScaleFactor = screenWidth/osuWidth; | ||
let heightScaleFactor = screenHeight/osuHeight; | ||
let absolutePosition = new PIXI.Point(0, 0); | ||
switch (origin) { | ||
case Origin.Custom: | ||
case Origin.TopLeft: | ||
absolutePosition.set(position.x, position.y); | ||
break; | ||
case Origin.TopCenter: | ||
absolutePosition.set((osuWidth/2) + position.x, position.y); | ||
break; | ||
case Origin.TopRight: | ||
absolutePosition.set(osuWidth + position.x, position.y); | ||
break; | ||
case Origin.CenterLeft: | ||
absolutePosition.set(position.x, (osuHeight/2) + position.y); | ||
break; | ||
case Origin.Center: | ||
absolutePosition.set((osuWidth/2) + position.x, (osuHeight/2) + position.y); | ||
break; | ||
case Origin.CenterRight: | ||
absolutePosition.set(osuWidth + position.x, (osuHeight/2) + position.y); | ||
break; | ||
case Origin.BottomLeft: | ||
absolutePosition.set(position.x, osuHeight + position.y); | ||
break; | ||
case Origin.BottomCenter: | ||
absolutePosition.set((osuWidth/2) + position.x, osuHeight + position.y); | ||
break; | ||
case Origin.BottomRight: | ||
absolutePosition.set(osuWidth + position.x, osuHeight + position.y); | ||
break; | ||
} | ||
absolutePosition.x = (absolutePosition.x + (wideScreen? ((osuWidth - osuWidth43)/2) : 0)) * widthScaleFactor; | ||
absolutePosition.y *= heightScaleFactor; | ||
return absolutePosition; | ||
} | ||
} |