oprypin / crsfml

Crystal bindings to SFML multimedia/game library
https://oprypin.github.io/crsfml
zlib License
350 stars 14 forks source link

Position seems to double when += 1 #17

Closed bararchy closed 7 years ago

bararchy commented 7 years ago

My code to move the sprite up and down (Y) is this:

      when SF::Keyboard::Down
        position = sprite.position
        sprite.move(SF.vector2(position.x, position.y - 1))
        window.clear
        window.draw(sprite)
        window.display
      when SF::Keyboard::Up
        position = sprite.position
        sprite.move(SF.vector2(position.x, position.y + 1))
        window.clear
        window.draw(sprite)
        window.display

Now, it seems that the - part is not affecting the sprite position at all, and the sprite position will only increase, and not by 1 at a time but by x2, here is print of the position:

SF::Vector2(Float32)(@x=0, @y=2)
SF::Vector2(Float32)(@x=0, @y=4)
SF::Vector2(Float32)(@x=0, @y=8)
SF::Vector2(Float32)(@x=0, @y=16)
SF::Vector2(Float32)(@x=0, @y=32)
SF::Vector2(Float32)(@x=0, @y=64)
SF::Vector2(Float32)(@x=0, @y=128)
SF::Vector2(Float32)(@x=0, @y=256)
SF::Vector2(Float32)(@x=0, @y=512)
SF::Vector2(Float32)(@x=0, @y=1022)
SF::Vector2(Float32)(@x=0, @y=2044)
SF::Vector2(Float32)(@x=0, @y=4088)
SF::Vector2(Float32)(@x=0, @y=8176)
SF::Vector2(Float32)(@x=0, @y=16352)
SF::Vector2(Float32)(@x=0, @y=32704)
SF::Vector2(Float32)(@x=0, @y=65408)
SF::Vector2(Float32)(@x=0, @y=130816)
SF::Vector2(Float32)(@x=0, @y=261632)
SF::Vector2(Float32)(@x=0, @y=523264)

What am I missing ? :)

nicck commented 7 years ago

http://oprypin.github.io/crsfml/api/SF/Transformable.html#move%28offset%3AVector2%7CTuple%29-instance-method

def move(offset : Vector2 | Tuple)

move method accepts offset, not position, m/b this is the reason

oprypin commented 7 years ago

Replace move with position= or use move with SF.vector2(0, -1) etc