Created
May 9, 2018 20:48
-
-
Save erfg12/b50abced332f655fa36be3ec17474b02 to your computer and use it in GitHub Desktop.
GameMaker 1.4 Flip X Y Coordinates
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
// If you're trying to give X Y coordinates over a network and you need to flip them on the client side, here's how it can be done. | |
// global.bx = server sending ball X coordinate | |
// global.by = server sending ball Y coordinate | |
// This code should be placed in your ball object's step. | |
//show_debug_message("[DEBUG|BALL|REAL] bx:" + string(global.by) + " by:" + string(global.by) + " w/2:" + string(room_width/2) + " h/2:" + string(room_height/2)); | |
//build a fake grid | |
fakex = global.bx - (room_width/2); | |
fakey = global.by - (room_height/2); | |
//show_debug_message("[DEBUG|BALL|GRID] fake-x:" + string(fakex) + " fake-y:" + string(fakey)); | |
//flip coordinates | |
if (sign(fakex) == -1) | |
fakex = abs(fakex); | |
else | |
fakex = fakex * -1; | |
if (sign(fakey) == -1) | |
fakey = abs(fakey); | |
else | |
fakey = fakey * -1; | |
//show_debug_message("[DEBUG|BALL|FLIPPED] fake-x:" + string(fakex) + " fake-y:" + string(fakey)); | |
//remove fake grid | |
fakex = fakex + (room_width/2); | |
fakey = fakey + (room_height/2); | |
//show_debug_message("[DEBUG|BALL|RESTORE] fake-x:" + string(fakex) + " fake-y:" + string(fakey)); | |
//move ball to reversed coordinates | |
x = fakex; | |
y = fakey; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment