RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Centering Algorithm

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 85
Real Men Make Fan Games
Project of the Month winner for May 2009
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 ^_^




*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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

*
Rep:
Level 85
Real Men Make Fan Games
Project of the Month winner for May 2009
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.
« Last Edit: February 13, 2009, 02:58:45 AM by madriel222 »




*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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.

*
Rep:
Level 85
Real Men Make Fan Games
Project of the Month winner for May 2009
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 ^_^




*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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