SDK 1.9.3 - Linux
Hi all,
I'm trying to wrap my head around this particular callback on the sprites when working on some game code. It is not an absolute blocker as I can get around it in other ways, but when trying to write test code to understand it, I get unexpected results and wanted a second opinion.
This is the main part of my test code:
seaweed_image = gfx.image.new("seaweed.png")
seaweed = gfx.sprite.new(seaweed_image)
seaweed:moveTo(sea_x, sea_y)
seaweed:setCollideRect(0, 0, seaweed:getSize())
seaweed.type = "seaweed"
seaweed:add()
fish_image = gfx.image.new("fish.png")
fish = gfx.sprite.new(fish_image)
fish:moveTo(x, y)
fish:setCollideRect(0, 0, fish:getSize())
fish.type = "fish"
fish:add()
fish.collisionResponse = function(other)
print(other.type)
return gfx.sprite.kCollisionTypeSlide
end
I have issues with collisionResponse
. In my update function I have controls over the fish and when I move the fish into the seaweed, i get a printout fish
, not seaweed
as I would have expected reading the doc on this callback:
A callback that can be defined on a sprite to control the type of collision response that should happen when a collision with other occurs
By this definition, I would have expected an output seaweed
as it is the fish that is colliding with the other sprite seaweed
, but instead I get other being fish (in this case, self) which to me seems backwards. I am new to Lua so I might have written something incorrectly, but even tutorials like this hint at the sprite other being defined as something you collide with.
Can someone please help me understand this?
I have added the actual code I'm running if anyone is interested. example.zip (13.3 KB)
Thank you in advance.