Expanding sprite doesn't fire collision

Firstly, hello to everyone. I’m new here and this is my first post.

I’m having a little issue regarding sprite collision detection. I can make one box falling on another work fine, so I think I’ve got the hang of it in principle. However, I am doing something a little different.

I am creating a new 64x64 sprite scaled down to 8x8. During the game loop I am then expanding it until it’s reached its full size. All ok so far.
My problem is I want to detect a collision if another box expands into an existing one. It would seem the onCollision event doesn’t fire if the sprite itself doesn’t “move” into the space of the other.

Is there a way to check if an expanding sprite touches another (as opposed to a moving sprite)?

Thanks! [import]uid: 8683 topic_id: 1934 reply_id: 301934[/import]

Just to add some more info - I am adjusting width & height values to expand the sprite.

Also, because I don’t want the physics engine to apply any gravity, I’ve got them as static (I’ve also tried kinematic).
Not being very well versed in the physics engine (I’ve only had the thing for a day!) I don’t know how to turn off the gravity for a dynamic body.
Don’t know if that’s relevant.

EDIT —

Ok, just read in another topic that collisions don’t occur unless at least one of the bodies is dynamic. That would explain it then.
Assuming this is correct, my next question is how do I stop the object falling? I’ll start another thread for that one (after I do a little more reading!). [import]uid: 8683 topic_id: 1934 reply_id: 5704[/import]

Ok, made some progress.
Finally learned how to switch off gravity with

physics.setGravity( 0, 0 )  

There’s no collision testing while I’m manipulating the width & height.
If I wait until the box is at its maximum size and then do the addBody, it will then check to see if it’s touching another sprite and the collision fires just fine.

So, my revised question is does anyone know how to check for collisions while a sprite is being adjusted by its height & width properties?
Or, has anyone got a better way of doing it altogether?

Many thanks, [import]uid: 8683 topic_id: 1934 reply_id: 5707[/import]

I dont think you can adjust the size of the object once physics is applied to it as that would mess up the physics calculations.

Ive been thinking about this recently and my solution ( not coded yet ) would be to have…

1 Group
Inside group - 1 image & 1 collision object ( for a square object )

I was thinking about writing a simple class to setup and assign some functions to each object

To resize the object I would write a function to resize the image and then recreate the collision object to the size and position of the resized image. I think the collision objects would need to be recreated for each frame of the resize or you layer 4 collision objects over each other and as the object expands they are locked to the 4 corners. This would allow the sprite to grow to double its size without having to recreate collision objects.

Im in planning mode at the moment so unfortunately it wont be for a couple of weeks until I jump in Corona and test this. [import]uid: 5354 topic_id: 1934 reply_id: 5747[/import]

Hi Matthew,
thanks for your response.

I shall squizz through it when I’m back home.

I’ve solved the immediate problem as I was just using squares, so I’ve dumped box2d and written a box collision function which works fine.

Cheers! [import]uid: 8683 topic_id: 1934 reply_id: 5748[/import]