Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Problem with detecting collision between circle and line.
Started by universalenglishinchina Feb 19 2015 01:00 AM

- - - - -
32 replies to this topic

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). 

[TOPIC CONTROLS]
Page 2 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#26

universalenglishinchina

[GLOBAL: userInfoPane.html]
universalenglishinchina
  • Contributor

  • 103 posts
  • Corona SDK

Tried. :( Didn't work. :(

[TOPIC: post.html]
#27

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,811 posts
  • Corona SDK

Strange one. I won't be back in front of my dev machine for a few hours, I can try running the code then.



[TOPIC: post.html]
#28

universalenglishinchina

[GLOBAL: userInfoPane.html]
universalenglishinchina
  • Contributor

  • 103 posts
  • Corona SDK

Thanks. That is why I tore everything else out and worked on these pieces only. It just appears to me that the groups are being treated differently by the touch and the collusion. Appreciate any assistance you can give me. Thanks!

[TOPIC: post.html]
#29

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @universalenglishinchina,

As general advice, I can't recommend that you try to add a physics body and sense collision detection on a group (display group). Groups and physics can be a difficult mix and you shouldn't move groups around independently of other groups when you're trying to detect physics collisions.

 

Take care,

Brent



[TOPIC: post.html]
#30

universalenglishinchina

[GLOBAL: userInfoPane.html]
universalenglishinchina
  • Contributor

  • 103 posts
  • Corona SDK

So, are you saying I cannot have a bunch of circles on the screen where I wrote inside them?  Like numbers and letters?  And try to detect collisions?

 

I have to make png's of all those items I want????



[TOPIC: post.html]
#31

universalenglishinchina

[GLOBAL: userInfoPane.html]
universalenglishinchina
  • Contributor

  • 103 posts
  • Corona SDK

Let's assume I cannot do what I want (that would be terrible!).

 

Is there a way to check (without countless iterations) to know when each object is at a certain y position (like if ypos < 50 from bottom.)

If I MUST (really last resort) as long as I can know right when it disappears off edge.  But MUCH prefer just a piece of it is going off edge.

 

Goal is put a math problem in circle and if they don't select it because they think it is wrong and it hits floor then do something.  Like take points away and flash letting them know they made a mistake.

So, I thought about collusion of the group with the floor.  but, you said no.  So, is there another way to solve this WITHOUT me having my artist draw 1,000,000 circles with unique math problems in the middle????



[TOPIC: post.html]
#32

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,811 posts
  • Corona SDK

  Best Answer

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). 



[TOPIC: post.html]
#33

universalenglishinchina

[GLOBAL: userInfoPane.html]
universalenglishinchina
  • Contributor

  • 103 posts
  • Corona SDK

Thank you - I found what you are referring to for number 2.

I saw how many times it runs, my goodness.  Isn't that labor intensive for the mobile devices?

 

But, it does work like a charm!

 

Thank you SOOO much for your extensive help and thanks Brent for being the bearer of bad news!  haha - at least it made it possible to find a solution quickly.

 

Thank you!




[topic_controls]
Page 2 of 2 1 2
 
[/topic_controls]