本帖最后由 沙漠点灰 于 2013-8-10 16:08 编辑
lz说的是缓动的话,可以试试:
#encoding:utf-8 #============================================================================== # ■ Sprite #------------------------------------------------------------------------------ # RGSS #============================================================================== class Sprite #-------------------------------------------------------------------------- # ● 移动到 #-------------------------------------------------------------------------- def move_to(x, y, zoom, duration, opa=nil) @old_x = self.x @old_y = self.y @target_x = (x ? x : self.x) @target_y = (y ? y : self.y) @old_zoom = self.zoom_x @target_zoom = (zoom ? zoom : self.zoom_x) @target_opa = (opa ? opa : @target_opa) @old_opa = self.opacity @duration = duration @duration_full = duration.to_f end #-------------------------------------------------------------------------- # ● 刷新移动 #-------------------------------------------------------------------------- def move_update return true if @duration.nil? or @duration <= 0 @duration -= 1 var = 1-Math.f(@duration/@duration_full+1) self.x = (@old_x + (@target_x-@old_x) *var+0.5).to_i self.y = (@old_y + (@target_y-@old_y) *var+0.5).to_i self.zoom_x = @old_zoom + (@target_zoom-@old_zoom) *var self.zoom_y = self.zoom_x self.opacity = (@old_opa + (@target_opa - @old_opa)*var+0.5).to_i if @target_opa false end end def Math.f(x) return self.f(x+2) if x < 0 return self.f(x-2) if x >= 2 (x-1)**2 end
#encoding:utf-8
#==============================================================================
# ■ Sprite
#------------------------------------------------------------------------------
# RGSS
#==============================================================================
class Sprite
#--------------------------------------------------------------------------
# ● 移动到
#--------------------------------------------------------------------------
def move_to(x, y, zoom, duration, opa=nil)
@old_x = self.x
@old_y = self.y
@target_x = (x ? x : self.x)
@target_y = (y ? y : self.y)
@old_zoom = self.zoom_x
@target_zoom = (zoom ? zoom : self.zoom_x)
@target_opa = (opa ? opa : @target_opa)
@old_opa = self.opacity
@duration = duration
@duration_full = duration.to_f
end
#--------------------------------------------------------------------------
# ● 刷新移动
#--------------------------------------------------------------------------
def move_update
return true if @duration.nil? or @duration <= 0
@duration -= 1
var = 1-Math.f(@duration/@duration_full+1)
self.x = (@old_x + (@target_x-@old_x) *var+0.5).to_i
self.y = (@old_y + (@target_y-@old_y) *var+0.5).to_i
self.zoom_x = @old_zoom + (@target_zoom-@old_zoom) *var
self.zoom_y = self.zoom_x
self.opacity = (@old_opa + (@target_opa - @old_opa)*var+0.5).to_i if @target_opa
false
end
end
def Math.f(x)
return self.f(x+2) if x < 0
return self.f(x-2) if x >= 2
(x-1)**2
end
sprite_obj.move_to(目标X坐标[nil时不改变], 目标Y坐标[nil时不改变], 目标放大率[nil时不改变], 移动帧数[, 目标不透明度(nil时不改变)])
每帧需要调用sprite_obj.move_update
这个效果是刚开始(改变速度)比较快,越接近目标,(改变速度)越慢
将Math.f(x)改为三角(Sin)函数的话,能做成开始和结束比较慢,中间比较快。
PS:
Math.f(x)定义域为[0, 2),值域为[0, 1]
PS2:
自己开始时也用三角函数,但是后来就直接二次函数了,
毕竟效果又好计算又快
-----------------------------------------------------
@end55rpg
(x-1)**2换成1-(x-1)**2就行了 |