搜索附件  

位图wave效果: Wave.zip

 

位图wave效果:
直接代码
RUBY 代码
[code]class Bitmap
  def to_int
    self.object_id
  end

  # src_bitmap    源位图,必须与自身位图同尺寸
  # wave_length  【无符号整型】   波长对应一个Math::PI
  # wave_amp     【无符号整型】   波高
  # wave_speed   【基本整型】     影响波动快慢
  # wave_phase   【基本整型】     波动起始的角度值(一般0...360)
  def wave(src_bitmap, wave_length, wave_amp, wave_speed = 1, wave_phase = 0)
    @src_bitmap = src_bitmap
    @wave_length = wave_length
    @wave_amp = wave_amp
    @wave_speed = wave_speed   
    @wave_phase = wave_phase
    @waving = (wave_length * wave_amp * wave_speed != 0)

    # 说明用变量
    @wave_step = Math::PI / wave_length
    @wave_dcos = Math.cos(@wave_step) * 2
  end

  # 说明用方法: WaveH 的RGSS 实现
  def wave_update
    returnunless@waving
    self.clear

    rad = @wave_phase * Math::A2R
    s0 = Math.sin(rad)
    s1 = Math.sin(rad + @wave_step)
    s2 = 0

    src_rect = Rect.new(0, 0, @src_bitmap.width, 1)
    self.blt((s0 * @wave_amp).round, 0, @src_bitmap, src_rect)

    src_rect.y += 1
    self.blt((s1 * @wave_amp).round, 1, @src_bitmap, src_rect)

    2.upto(self.height - 1)do |y|
      s2 = @wave_dcos * s1 - s0
      s0, s1 = s1, s2

      src_rect.y += 1
      self.blt((s2 * @wave_amp).round, y, @src_bitmap, src_rect)
    end

    @wave_phase = (@wave_phase + @wave_speed) % 360
  end


  dll = "Wave.dll"
  WaveH = Win32API.new(dll, 'bitmapWaveH', 'LLLLLL', 'V')
  def wave_update_dllH
    returnunless@waving
    @wave_phase = WaveH.call(self, @src_bitmap, @wave_phase,
      @wave_length, @wave_amp, @wave_speed)
  end

  # 适用于250 * 250大小以下的位图
  WaveV = Win32API.new(dll, 'bitmapWaveV', 'LLLLLL', 'L')
  def wave_update_dllV
    returnunless@waving
    @wave_phase = WaveV.call(self, @src_bitmap, @wave_phase,
      @wave_length, @wave_amp, @wave_speed)
  end

  WaveV_line4 = Win32API.new(dll, 'bitmapWaveV_line4', 'LLLLLL', 'L')
  def wave_update_dllV_line4
    returnunless@waving
    @wave_phase = WaveV_line4.call(self, @src_bitmap, @wave_phase,
      @wave_length, @wave_amp, @wave_speed)
  end

  WaveHV = Win32API.new(dll, 'bitmapWaveHV', 'LLLLLL', 'L')
  def wave_update_dllHV
    returnunless@waving
    @wave_phase = WaveHV.call(self, @src_bitmap, @wave_phase,
      @wave_length, @wave_amp, @wave_speed)
  end
end



src = Bitmap.new("temp2.jpeg")
#src.fill_rect(src.rect, Color.new(0, 255, 255))

sprite = Sprite.new
sprite.bitmap = Bitmap.new(src.width, src.height)
sprite.bitmap.wave(src, 50, 10, 2, 0)
sprite.x = 320
sprite.y = 240
sprite.ox = src.width / 2
sprite.oy = src.height / 2


str = "Bitmap(#{src.width} * #{src.height})\n"
count, t = 0, Time.now
loopdo
  sprite.bitmap.wave_update_dllH
  breakifTime.now - t >= 1.0
  count += 1
end
str = 1.0
  count += 1
end
str = 1.0
  count += 1
end
str = 1.0
  count += 1
end
str
Loading...

QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

GMT+8, 2024-11-22 04:35 , Processed in 0.051322 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

返回顶部