vrld / HC

General purpose collision detection library for the use with LÖVE.
http://hc.readthedocs.org/
402 stars 48 forks source link

Getting the x/y of a object added. #22

Closed flexd closed 11 years ago

flexd commented 11 years ago

How is this possible?

I'm moving my camera based on my player object, which is now a Collission:addRectangle() shape, but I can't seem to use player.x/y any more.

How can I get the position of the rectangle/object?

I want to be able to do something like this

camera:setPosition(player.x - width / 2, player.y - height / 2)
vrld commented 11 years ago

You can get the shape center using shape:center(). You can also move the shape with shape:move(dx,dy) and shape:moveTo(x,y).

flexd commented 11 years ago

shape:center() is not returning y at all,

trying to print("Player: ", player:center()) and getting just "Player: 404" where 404 = X.

vrld commented 11 years ago

Works fine at my end:

r = (require 'HardonCollider')():addRectangle(10,10,100,100) print('center:', r:center()) --> center: 60 60

Are you sure you are not discarding values (see section 2.5 of the Lua manual)? I.e. doing something like:

print("Player: " .. player:center()) print("Player: ", player:center(), "stuff")

flexd commented 11 years ago

I'm doing this exactly:

local position = player:center()
print("Position is: ", position)

And getting this out:

Position is:    425
Position is:    425
Position is:    425
Position is:    425
Position is:    425
Position is:    425
Position is:    425
Position is:    425
Position is:    425
Position is:    425
Position is:    425
Position is:    425
Position is:    425
Position is:    425
Position is:    425
Position is:    425
camoy commented 11 years ago

There's your problem, you're only retaining one value!

local x, y = player:center()
print("Position is: ", x, y)
flexd commented 11 years ago

Oh, sneaky!

flexd commented 11 years ago

Now I just need to get the camera controls working properly and we are in business! Thanks for the help :)