Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module TSBS
- #============================================================================
- # Easing movement just in case. Thanks to Galenmereth
- # ---------------------------------------------------------------------------
- # time = Current time (frame)
- # start = Start value
- # change = Desired change in value
- # duration = Duration total (frames)
- # Returns: Value modified by t
- # ---------------------------------------------------------------------------
- # * Easing movement method : Linear
- # ---------------------------------------------------------------------------
- def self.linear(time, start, change, total_time)
- return change * time / total_time + start
- end
- # ---------------------------------------------------------------------------
- # * Easing movement method : Smooth in
- # ---------------------------------------------------------------------------
- def self.smooth_in(time, start, change, total_time)
- time /= total_time.to_f
- return change*time*time*time + start
- end
- # ---------------------------------------------------------------------------
- # * Easing movement method : Smooth out
- # ---------------------------------------------------------------------------
- def self.smooth_out(time, start, change, total_time)
- time /= total_time.to_f
- time -= 1
- return change*(time*time*time + 1) + start
- end
- end
- class Sprite_Njajal < Sprite
- def initialize
- super()
- self.bitmap = Bitmap.new(32,32)
- bitmap.fill_rect(bitmap.rect, Color.new(255,255,255))
- self.x = 300
- self.y = 200
- @dur = 0
- @time = 0
- end
- def update
- super
- if @dur != @time
- self.x = TSBS.smooth_out(@time, @ori_x, @tx - @ori_x, @dur)
- self.y = TSBS.smooth_out(@time, @ori_y, @ty - @ori_y, @dur)
- @time += 1
- end
- end
- def smooth(tx,ty,dur)
- @ori_x = self.x
- @ori_y = self.y
- @tx = tx
- @ty = ty
- @dur = dur
- @time = 0
- end
- end
- $sprite = Sprite_Njajal.new
- loop do
- Graphics.update
- Input.update
- $sprite.update
- if Input.trigger?(:C)
- $sprite.smooth(100,100,60)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment