Hi there, hopefully somebody can help on this one - been trying all day and I think I'm at the point where my brain is about to melt 😛
So in our game we are storing the Players X and Y co-ordinates every 60 frames. These are stored into variables 26 and 27 respectively.
What I am in need of is a way of scaling the X co-ordinate (variable 26) as a number within the range 0 to 1024 (it can be a whole number)
And the Y co-ordinate (variable 27) scaled as a number within the range 0 to 768 (again it can be a whole number)
Is there a way of storing these scaled values into a new set of variables with the script variable function? If so, how?
Absolutely happy to pay / donate for the right solution.
Okay, judging by the numbers this is your screen resolution. So you actually want to get the real x y coordinates of the player on the screen in pixels, I guess?
This can be done with event commands:
Control variable -> Game Data -> Character -> Screen X
Or with script calls:
$gamePlayer.screenX()
I know this isn't exactly what you asked but I tried answering the spirit of the question.
You could calculate all that by getting tile coordinates, multiplying them by the width and height and knowing where the display is right now, but why would you bother since you have the function ready?
Please look at this thread to get the list of the equivalent of event commands as script calls:
You'd use:
$gameVariables.value(id) //to return the value of a variable
$gameVariables.setValue(id,value) //to set the value of a variable
Combining those script calls should get you the desired effect.
If I'm wrong:
Why are you trying to "scale" those variables? I could tell you to use the mod operator. This way you'd always get a result between 0 and 1024 or 0 and 762, or you could use simple calls such as Math.max and Math.min to make it always >= 0 and < to your upper limit but you'd likely get unusable result if you were trying to have those still refer to the player coordinates.
This is just a matter of simple math then.
Your base resolution is 180*150, your target resolution is 1024*768.
Lets say you have point 50,40 in your 180*150 resolution you want to make it into 1024 * 768:
Just multiply by the quotient bewteen your two resolutions:
50 * (1024/180) = 284
40 * (768/150) = 204,4
There you go, you have your new coordinates.
No I think I'm getting there now - feel free to pass me the dunce hat! However the game runs in 1024x768 constantly, and the map jpeg i'm displaying is 1024x768 too.
I'm basically asking what calculation I need to get the X and Y pixel co-ordinate on a 1024x768 screen based of the location of the player on a 180 by 150 tile map
Really sorry, if it seems like I'm stupid here, maybe I am 🙂
I'm going to respectfully decline. This was simple, didn't take much of my time, and I certainly did not do it for the money.
I'm helping people learn because I like it, because I like solving problems and because it helps me learn too.
Not to mention I don't have a paypal account 😛 . Now , if you are some crazy billionaire who would like to give me millions over this, do tell, I'll be happy to arrange matters 🙂
Joking aside:
Have a beer on me to celebrate having learned something, give it to people more in need than me, or keep it,... Your thanks are enough to show your appreciations, don't worry.
Cheers!