This is probably a dumb question but because the code looks solid I have no idea what it could be.
I have 2 sprites. After their y becomes 0 they refuse to move any further (works as long a their y-value is < 0). Changing the VELOCITY to 1 or greater fixes the problem. Why? Why does @bg1.y += 0.5 not work but @bg1.y += 1 does?
Note that bitmap.height and Graphics.height both equal 480.
Sample Code:
class Scrolling_BG_Vertical VELOCITY = 0.5 # BUG: any velocity < 1 will bug and will not move the sprite down after it reaches "bg1.y == 0" or "bg2.y == 0" #VELOCITY = 1 # <<< works #VELOCITY = 0.9 # <<< bugs def initialize(image) @bg1 = Sprite.new @bg1.bitmap = Cache.test(image) @bg1.x = 0 @bg1.y = 0 @bg1.z = 1 @bg2 = Sprite.new @bg2.bitmap = Cache.test(image) @bg2.x = 0 @bg2.y = -@bg2.bitmap.height @bg2.z = 1 end def update @bg1.y += VELOCITY @bg1.y = -@bg1.bitmap.height if @bg1.y == Graphics.height @bg2.y += VELOCITY @bg2.y = -@bg2.bitmap.height if @bg2.y == Graphics.height p 'just making sure that update is being called every frame' endend
Is the float being rounded down somewhere in the Sprite class?
Also:
Code:
p @bg1.y # => 0@bg1.y += 0.5p @bg1.y # => 0.... wut... still 0?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.