I've been trying at this for a little bit but I can't get it. I'm trying to make a sprite work with floating points so I don't need to externally keep track of where the Sprite should be. Like if I try moving a Sprite +2.5 pixels in the x and +1.5 pixels in the y. It truncates the number and the path is wrong over time. And if you set the amount of movement per frame to a number less than zero it remains stationary. 0.5 becomes 0, heck 0.9 becomes 0. Anyway thats the reasoning behind this little object.
The problem is that either I'm screwing up the way I'm doing aliasing because where ever I tell the sprite to go gets ignored, or I'm not understanding what little I do about the Sprite object. In any case I made a nice little test script for anyone that might have any ideas on how to solve this.
Thanks for taking the time to read this. :thumb:
The problem is that either I'm screwing up the way I'm doing aliasing because where ever I tell the sprite to go gets ignored, or I'm not understanding what little I do about the Sprite object. In any case I made a nice little test script for anyone that might have any ideas on how to solve this.
Code:
#==============================================================================
# ** Sprite_Float < Sprite
#------------------------------------------------------------------------------
# A sprite whose coordinates are Floating point instead of Fixnum. So movement
# can be based on floating point math. No more 1.6 = 1 all the time nonsense.
#==============================================================================
Debug_Output = true
class Sprite_Float < Sprite
#--------------------------------------------------------------------------
# * Alias Methods
#--------------------------------------------------------------------------
alias_method :khmp_sprite_float_x=, :x=
alias_method :khmp_sprite_float_y=, :y=
alias_method :khmp_sprite_float_z=, :z=
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super()
@fx = @fy = @fz = 0.0
end
#--------------------------------------------------------------------------
# * x=
# x : the new x coordinate
#--------------------------------------------------------------------------
def x=(x)
p "Sprite_Float.x= has been called. x = " + x.to_s if Debug_Output
khmp_sprite_float_x=(@fx = x.to_f)
end
#--------------------------------------------------------------------------
# * y=
# y : the new y coordinate
#--------------------------------------------------------------------------
def y=(y)
p "Sprite_Float.y= has been called. y = " + y.to_s if Debug_Output
khmp_sprite_float_y=(@fy = y.to_f)
end
#--------------------------------------------------------------------------
# * z=
# z : the new z coordinate
#--------------------------------------------------------------------------
def z=(z)
p "Sprite_Float.z= has been called. z = " + z.to_s if Debug_Output
khmp_sprite_float_z=(@fz = z.to_f)
end
#--------------------------------------------------------------------------
# * x !OVERRIDE PARENT!
#--------------------------------------------------------------------------
def x
return @fx
end
#--------------------------------------------------------------------------
# * y !OVERRIDE PARENT!
#--------------------------------------------------------------------------
def y
return @fy
end
#--------------------------------------------------------------------------
# * z !OVERRIDE PARENT!
#--------------------------------------------------------------------------
def z
return @fz
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super()
end
end
#--------------------------------------------------------------------------
# Enable_Sprite_Test:
# True to "see" Sprite_Float
# False to see a regular Sprite instead
#--------------------------------------------------------------------------
Enable_Sprite_Test = true
class Scene_Title
alias_method :khmp_sprite_float_main, :main
def main
Enable_Sprite_Test ? @test = Sprite_Float.new : @test = Sprite.new
@test.bitmap = Bitmap.new(100, 100)
@test.bitmap.fill_rect(0, 0, 100, 100, Color.new(0, 0, 0))
@test.x = 80
@test.y = 50.0
@test.z = 100
p "@test.x = " + @test.x.to_s if Debug_Output
p "@test.y = " + @test.y.to_s if Debug_Output
p "@test.z = " + @test.z.to_s if Debug_Output
khmp_sprite_float_main
@test.bitmap.dispose
@test.dispose
end
end
Thanks for taking the time to read this. :thumb: