I’m trying to develop a tangram game. The problem I’m having is figuring out how to determine if the correct solution has been reached. Since a tangram is made of 7 shapes forming an image of something, I thought I could do some kind of bitmap check against the final image. I’m just not sure if that is a correct approach or if there is a better way to do it. [import]uid: 168506 topic_id: 30278 reply_id: 330278[/import]
Hi Betsy,
Although it might seem excessive, a valid method to check a “shape-based” layout is to use the physics system, specifically a sensor layout which senses if all of the shapes have been placed inside the boundaries. If this sounds reasonable for your app, I can give you more specific details about the method.
Brent [import]uid: 9747 topic_id: 30278 reply_id: 121311[/import]
Hi Brent,
I had seen the write-up concerning physics bodies but I wasn’t sure how to implement this. I didn’t know if I would have to define each tangram shape (the 7 individual pieces) and then how I would define the actual pattern to test against. Any help would be appreciated.
Betsy [import]uid: 168506 topic_id: 30278 reply_id: 121416[/import]
Hi Betsy,
I think the best method would be to surround your “valid shape area” with invisible physics sensors (isSensor=true). These can be just rectangles, rotated and overlapping a bit to surround your tangram shape area. The user would then need to fit the pieces into this region… if not, the task is not accomplished.
If you go down this route, you’ll also need to utilize a sensor overlap counter method, which I wrote about in the post linked below. The reason for this is: any time one physics body crosses into a sensor region, it registers a new collision “hit”. So, in your code, you need to keep track of how many sensors a piece is overlapping. One piece could easily overlap 2 or 3 sensors at a time, i.e. one corner of a box within one sensor and the opposite corner within another sensor… so you need to keep track of the count of overlaps on any given piece to ensure that they’re “clear” within the boundaries.
This might sound complicated, but it’s fairly straightforward. Hopefully the following post explains it better.
http://developer.coronalabs.com/forum/2012/04/07/no-collision-state
Check this out and please post any further questions here.
Brent
[import]uid: 9747 topic_id: 30278 reply_id: 121445[/import]
Hi Betsy,
Although it might seem excessive, a valid method to check a “shape-based” layout is to use the physics system, specifically a sensor layout which senses if all of the shapes have been placed inside the boundaries. If this sounds reasonable for your app, I can give you more specific details about the method.
Brent [import]uid: 9747 topic_id: 30278 reply_id: 121311[/import]
Hi Brent,
I had seen the write-up concerning physics bodies but I wasn’t sure how to implement this. I didn’t know if I would have to define each tangram shape (the 7 individual pieces) and then how I would define the actual pattern to test against. Any help would be appreciated.
Betsy [import]uid: 168506 topic_id: 30278 reply_id: 121416[/import]
Hi Betsy,
I think the best method would be to surround your “valid shape area” with invisible physics sensors (isSensor=true). These can be just rectangles, rotated and overlapping a bit to surround your tangram shape area. The user would then need to fit the pieces into this region… if not, the task is not accomplished.
If you go down this route, you’ll also need to utilize a sensor overlap counter method, which I wrote about in the post linked below. The reason for this is: any time one physics body crosses into a sensor region, it registers a new collision “hit”. So, in your code, you need to keep track of how many sensors a piece is overlapping. One piece could easily overlap 2 or 3 sensors at a time, i.e. one corner of a box within one sensor and the opposite corner within another sensor… so you need to keep track of the count of overlaps on any given piece to ensure that they’re “clear” within the boundaries.
This might sound complicated, but it’s fairly straightforward. Hopefully the following post explains it better.
http://developer.coronalabs.com/forum/2012/04/07/no-collision-state
Check this out and please post any further questions here.
Brent
[import]uid: 9747 topic_id: 30278 reply_id: 121445[/import]