Project1

标题: 地图上显示地图名、坐标 [打印本页]

作者: taroxd    时间: 2014-8-5 19:55
标题: 地图上显示地图名、坐标
本帖最后由 taroxd 于 2014-8-5 20:15 编辑

提问区回答问题写的。随手写的,所以写的结构很混乱。坐标什么的……懒得给你们设置了,自己调吧。反正都是变量= =

效果图: (, 下载次数: 127)
@Cache

[pre lang="ruby" line="1"]
module Cache
  @cache ||= {}
  def self.ellipse(a, b, color)
    key = [:ellipse, a, b, color]
    unless include?(key)
      @cache[key] = bitmap = Bitmap.new(2 * a, 2 * b)
      0.step(2*Math::PI, 0.01) do |theta|
        bitmap.set_pixel((a+a*Math.cos(theta)).to_i,
          (b+b*Math.sin(theta)).to_i, color)
      end
    end
    @cache[key]
  end
end

class Spriteset_Map
  alias cs_20140805 create_shadow
  def create_shadow
    cs_20140805
    @ellipse_sprite = Sprite.new
    a, b, c = 50, 40, Color.new(255,0,0)
    @ellipse_sprite.bitmap = Cache.ellipse(a,b,c).clone
    @ellipse_sprite.bitmap.fill_rect(0, b, 2*a, 1, c)
    @mapinfo_sprite = Sprite.new
    @mapinfo_sprite.bitmap = Bitmap.new(2*a, 2*b)
    @mapinfo_sprite.bitmap.font.size = 16
    @ellipse_sprite.x = 10
    @ellipse_sprite.y = 10
    @mapinfo_sprite.x = 10
    @mapinfo_sprite.y = 10
  end
  
  alias us_20140805 update_shadow
  def update_shadow
    us_20140805
    if @mapinfo_to_draw != mapinfo_to_draw
      n, x, y = @mapinfo_to_draw = mapinfo_to_draw
      text = "X:#{x} Y:#{y}"
      b = @mapinfo_sprite.bitmap
      b.clear
      b.draw_text(0,20,b.width,20,n,1)
      b.draw_text(0,40,b.width,20,text,1)
    end
  end
  
  alias ds_20140805 dispose_shadow
  def dispose_shadow
    ds_20140805
    @ellipse_sprite.bitmap.dispose
    @ellipse_sprite.dispose
    @mapinfo_sprite.bitmap.dispose
    @mapinfo_sprite.dispose
  end
  
  def mapinfo_to_draw
    [$game_map.display_name, $game_player.x, $game_player.y]
  end
end[/pre]   
作者: satgo1546    时间: 2014-8-5 20:13
卧槽为什么要画个椭圆直接画个渐变多好看啊……
作者: rpg5856    时间: 2015-10-20 20:44
{:2_275:}收下。看看
作者: 庆少秋风    时间: 2015-10-21 23:38
看看不说话{:2_274:}
作者: 7112    时间: 2016-7-16 13:41
看起来不错的样子
作者: 有丘直方    时间: 2016-7-16 18:25
椭圆……为何不用Window的windowskin?
作者: 汪洋洋    时间: 2016-8-8 14:28
请问下大大 能不能用公共事件在物品中显示坐标  不在地图上显示 用物品才显示当前坐标




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X5.0