Main Menu
  • Welcome to The RPG Maker Resource Kit.

Centering Algorithm

Started by madriel222, February 13, 2009, 01:52:26 AM

0 Members and 1 Guest are viewing this topic.

madriel222

Having some problems coming up with a formula/code that can center a 640x640 picture on a 40x40 map (rm2k3) dependent on player position.  In other words, the player can access the map from any square, so showing the picture would require that I first find out where the center of the map is in comparison to the player position.  Any help would be greatly appreciated ^_^




modern algebra

I'm not entirely certain that I know what you mean. DO you mean centre the picture on to the actor sprite? Or show the map such that it shows the quadrant the actor is in?

Either way, I think we are looking at variables: Sprite: Hero: Screen-Relative X, Y if you want it in relation to the screen   OR   X coordinate Y coordinate if you want plater position in relation to the map

madriel222

#2
Sorry, I'll try to elaborate that a little better  :)

I have a 40x40 map that I want to show a total overlay on.  The picture, therefore, is 640x640 (the total dimensions of a 40x40 tile map).  This picture needs to be centered on the map.  In other words, the center of the 640x640 picture needs to be, at all times, on the center of the 40x40 map.

At any given point on the map, you can make adjustments to make that happen.  Find the location of the hero, add or subtract based on that location, and show the picture at the resultant points.  If you have total control over where the hero enters the map from, then it's pretty easy to manually create those adjustments.  But what if I don't have control?  What if the player can enter the map onto any given tile?

Keep in mind that the screen ceases to move before the player does (going to the sides of the map, for example. the player keeps going left or right, but the screen is stationary).

I would like some kind of formula or method that can find the necessary adjustments at any given point on the map.  The hero is at (X,Y), the picture gets shown at (X',Y'). 

Hope we can get this sorted out ^_^

EDIT: Yet to try it, but I think this might work:

Set [Hero X] to hero's X coordinate.
Set [Hero Y] to hero's Y coordinate
***next part checks for screen edges of a 40x40***
If [Hero X] is less than 10, set it to 10
If [Hero X] is greater than 28, set it to 28
If [Hero Y] is less than 7, set it to 7
If [Hero Y] is greater than 31, set it to 31
***next part gets the distance from center in pixels***
[Hero X] +/-20 (sign determined by whether the Var is already greater than or less than 20)
[Hero Y] +/-20
[Hero X] *16
[Hero Y] *16
***lastly, flipping the signs to give coordinates***
[Hero X] * -1
[Hero Y] * -1

I think that has a shot to work.




modern algebra

OK, well try this maybe:

I won't guarantee, because I couldn't figure out how to import anything, but the basic thought I had was this: Find the coordinates of the upper left corner of the screen, and then place it backwards from there.

I am thinking there is a way to do this without going to the centre first, but that's the way I decided to tackle the problem.

madriel222

I think we're thinking along the same lines.  I'm just going from another direction, from the center to the player instead of the other way around.  On paper I think either of these are going to work.  Thanks ^_^




modern algebra

heh, yeah. I didn't even realize you had edited your post. I had the reply screen open for a long time before I got around to posting it :P