Hi! i've restarted at coding my collision system... for simple axis oriented collision
Sprite:getBounds(targetSprite) is very useful but i found a problem... (POSSIBLE BUG?)
The Problem
my sprite is 32x32px
if i scale x=2 and y=2 getBounds return width and height = 64 -> and is correct,
but
if i scale x=2 and y=1 getBounds return width = 64 (correct) and height (64) -> ERROR
it should be height = 32px?
i'm missing something or is a bug ?
@atilim i'm wrong ?
LUA CODE:
local ax, ay, ah, aw = self:getBounds(self.parent)
local bx, by, bh, bw = spriteB:getBounds(self.parent)
where (in my test code) self.parent is = "stage"
thanks,
Gianluca.
Comments
This simple example works as expected:
yes... my fault!!!
as you can see i swapped width and height
local ax, ay, ah, aw = self:getBounds(self.parent)
----------^^^^^^
local bx, by, bh, bw = spriteB:getBounds(self.parent)
------------^^^^^^
so my code not work!.
sorry... ">
ahhh!!! 8-X
Dislikes: GregBUG
www.tntengine.com
Likes: ar2rsawseen
yes sprite:getBounds(sprite) return the box that contain the sprite...
but if the sprite is rotated bound box size is increased... so if i transform transformation is not correct...
i mean... (getBounds in RED)
www.tntengine.com
but x and y are always 0
so the problem is when
local sprite = Bitmap.new(Texture.new("tntBox2.png"))
sprite:setPosition(160, 120)
sprite:setAnchorPoint(0,0)
stage:addChild(sprite)
print(sprite:getBounds(stage))
sprite:setRotation(45)
print(sprite:getBounds(stage))
now i get x and y coords, but w and h are wrong...
www.tntengine.com
getBounds work fine...
but is not what i need....
i mean
when spirte is not rotated bBox returned is perfect (coincide with the sprites) so collision is perfect....
but when i rotate the sprite bbox is not what i need...
I thought that "getBounds" returned original bbox also when the sprite is rotated...
(i need the bbox of sprite angle = 0 then i rotate it according to the angle sprites so i get perfect oriented bBox) ...
sorry but my english is poor! and i don't know how to explain better
www.tntengine.com
are u trying to say this
0 0 1024 768 ----- width and height is perfect
-31.057983398438 384 1267.1353759766 1267.1352539062 ---x and y are perfect
0 0 1024 768
512 384 1024 768
Or get the untransformed bounds and move it to stage's coordinate system:
thanks guys for help!
thanks!
www.tntengine.com