I imagine if you want it centered above the PC's head, you'd have to add the screen_x, half the player's bitmap width, and take away half the icon's width, for x; for y, it'd be screen_y minus the icon's height.
$game_player.x and y are the tile they're on, which has nothing to do with the screen.
What if I'm trying to also trying to center the text off of that position. then how would I determine the x and y's?
x = ($game_player.screen_x - (character_bitmap_width / 2)) - (Graphics.width / 2)Thanks Shaz!
The bottom one would be the correct way to figure out the x and y values. Like Shaz said though screen_x and screen_y would be the right ones to use, seeing as how they do that for you. That $game_player.x and $game_player.y gives you the map grid x and y, and each square is 32.
Does it work when you walk along the corner or edge of the map?
Oh sorry I should have clarified.
x = ($game_player.screen_x - (character_bitmap_width / 2)) - (Graphics.width / 2)is for centering the text with a centered alignment not the icons.
This is the bit of code for centering the icon and text
x = ($game_player.screen_x - (character_bitmap_width / 2)) - 4 y = $game_player.screen_y - 96 draw_icon(x, y, reward[0], reward[2]) draw_sizable_text((x - (Graphics.width / 2)) + 10, y - 170, Graphics.width, Graphics.height, string, 1, 14)This is the method I created to get the with
#-------------------------------------------------------------------------- # * Returns Character Graphic Dimensions #-------------------------------------------------------------------------- def character_bitmap_width character_name = $game_party.members[0].character_name bitmap = Cache.character(character_name) sign = character_name[/^[\!\$]./] if sign && sign.include?('$') cw = bitmap.width / 3 else cw = bitmap.width / 12 end return cw endI guess I should do this for the height too though, in the case that the sprite is tall too.
#-------------------------------------------------------------------------- # * Returns Character Graphic Dimensions #-------------------------------------------------------------------------- def character_bitmap_dimensions character_name = $game_party.members[0].character_name bitmap = Cache.character(character_name) sign = character_name[/^[\!\$]./] if sign && sign.include?('$') cw = bitmap.width / 3 ch = bitmap.height / 4 else cw = bitmap.width / 12 cw = bitmap.height / 8 end return [cw, ch] endThanks again. This post can be closed.
Actually While I'm on the topic maybe someone can help me out. I've noticed that I always have to add or minus 10 when centering text to the screen.
Does anyone know the reason for this?
No, you don't need to do it for the height. screen_x, screen_y is the upper left corner of the sprite, not the base. It does NOT coordinate with a tile on the grid.
When looking at the grid tile occupied by the character, you look at the BASE of the sprite. But screen_y is the TOP of the sprite. So you don't have to subtract the sprite's height. Your - 96 will put the icon 3 tiles above the top of the sprite. I don't think that's what you want.
ah, okay - didn't realize you wanted icon and text one above the other.
Alrighty, then ... I guess This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.