Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
what you set to setPosition is not exactly what you get from getPosition — Gideros Forum

what you set to setPosition is not exactly what you get from getPosition

XmanXman Member
edited October 2015 in General questions
local s1 = Sprite.new()

stage:addChild(s1)

---331.81048583984
s1:setPosition(331.81047773361, 331.81047773361)

print(s1:getPosition())

output
331.81048583984 331.81048583984 0

that's make it impossible to do collision check by x, y position

Comments

  • hgy29hgy29 Maintainer
    Thats because coordinates in gideros are stored as 32bit floats (single precision), wheras the number you try to set would have required double precision (64 bits). Check with this online tool: http://www.h-schmidt.net/FloatConverter/IEEE754.html

    However this shouldn't prevent you from doing collision tests by checking if the position is inside some range.

    Likes: Holonist

    +1 -1 (+1 / -0 )Share on Facebook
  • That really make it impossible to determine whether the bottom of an object is just on the surface of the top of another. That puzzled me all day to figure it out. Finally,I solved it by keeping the position value in the object itself.

  • HolonistHolonist Member
    edited October 2015
    In your example, the difference starts at the fifth decimal.
    If you have to check your objects in ranges of a 10000th PIXEL (a pixel is actually the smallest amount that you can move an object on the screen), I don't believe your game design is appropriate.

    Maybe you're missing the usage of >=, <= operators instead of ==?
Sign In or Register to comment.