Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

$game_map.display_x & $game_map.display_x

-Dan-

Member

Hay guys, I have simple question - how to calculate display_x and display_y variables for events? Cause $game_map.display_x for example shows me number which is referencing to the player.

I tried $game_map.events[Event_ID].display_x/y but then the error apparents. The help file is out of any informations about it :< Thanks for any reply.
 
Actually, what you'll need is the following:

Code:
x = $game_map.events[event_id].x

y = $game_map.events[event_id].y

Incidentally, you can also dig through the default scripts in an attempt to find what isn't mentioned in the help file. In this case, you could have found what you were looking for by looking in Game_Map, finding that events were instances of Game_Event, and finding that Game_Event was derived from Game_Character, then finally noticing that Game_Character has x and y values as public variables. It's complicated, I know, but it is just one more resource you can use.
 

-Dan-

Member

Thanks Glich, but probably you don't understand me XD

I don't want to display X and Y position of the events, I can use normal variables to do that in this same way...

$game_map.display_y shows value which is something like "y * 128 but only if the screen is scrolling". If the player positon Y is equal to 6 then $game_map.display_y is equal 0, but if player positon Y is 12 then $game_map.display_y is 640.

Look at this simple window:
Code:
class Window_Deb < Window_Base

  def initialize

    super(0, 0, 320, 160)

    self.contents = Bitmap.new(width - 32, height - 32)

    self.back_opacity = 160

    refresh

  end

  def refresh

    self.contents.clear

    self.contents.font.color = system_color

    self.contents.draw_text(4, 0, 200, 32, "$game_player.x:")

    self.contents.draw_text(4, 32, 200, 32, "$game_player.y:")

    self.contents.draw_text(4, 64, 200, 32, "$game_map.display_x:")

    self.contents.draw_text(4, 92, 200, 32, "$game_map.display_y:")

    self.contents.font.color = normal_color

    self.contents.draw_text(160, 0, 120, 32, $game_player.x.to_s, 2)

    self.contents.draw_text(160, 32, 120, 32, $game_player.y.to_s, 2)

    self.contents.draw_text(160, 64, 120, 32, $game_map.display_x.to_s, 2)

    self.contents.draw_text(160, 92, 120, 32, $game_map.display_y.to_s, 2)

  end

end

Effect when screen is not scrolled:
1steffect.png


Second effect when it is:
2ndeffect.png


Now do you understand ^^? I need to calculate this but not for player - for the event. The worst problem is that this value isn't only integer number which is divisible by 128, it have other values when the player is moving ;x
 
All right. Same place as where I directed you. If you notice, the two lines after the pair I directed you to reads as follows:

Code:
   attr_reader   :real_x                   # map x-coordinate (real * 128)

  attr_reader   :real_y                   # map y-coordinate (real * 128)

In other words, all you need to do is use .real_x and .real_y, even for the player, and most certainly for the events. Incidentally, if you had taken my advice to heart, you might have found this on your own. I'm not saying you have to learn everything at once, but it's always a good idea to dig through the related scripts when you are looking for something not mentioned by the help file.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top