Problem with detecting collision between circle and line.
Feb 19 2015 01:00 AM
Best Answer nick_sherman , 21 February 2015 - 12:05 AM
Sorry, I'd forgotten that using groups as physics objects was a no-no. Don't panic though - there's always a way!
2 options I can think of:
1) When you spawn a circle/text object, create it as a display group as you've done, then save that group as a snapshot to disk. Then destroy the group, load the image and then add the physics, myName etc. If you save them like 'circle_A_text_44', you can check whether that circle/text combination exists already and load it if so, or create the new snapshot if not.
I used this method on my app Football Faces: https://itunes.apple.com/us/app/id889897741?mt=8&ign-mpt=uo%3D8
All those images had the effects applied, then they were saved, destroyed, and re-loaded as normal images. I did this because applying live effects to all those images at once slowed the app to a crawl whenever they were scrolled.
2) Create the circle and text objects separately, making just the circle a physics object. Make the text object a child of the circle - i.e. c.text = text. Add both to sceneGroup.
Use a runtime enterFrame listener, which is a function that runs every frame. Then loop through all the circle objects that currently exist in the circles table, and do circles[i].text.x, circles[i].text.y = circles[i].x, circles[i].y. That way the text will follow its circle wherever it goes.
When you destroy the circle, remember to destroy the text object first. i.e. display.remove(obj.text).