@Lam
So far so good. But I wonder if there is more sophisticated method that you know that create (attach) the invisible poly to the animated sprite. My current method is just follow the spite with the polygon but I would like to see a shadow polygon follow automatically the animated sprite once you attach the polygon at the sprite creation. Anther nice feature is edge detection of the sprite so the polygon will wrap the sprite. I guess it is up to integration of Box2d to Cocos2d. Coming from imaging that can be done but I think this platform is too weak for that.
Thank again for the highlight, I really enjoy the mix approach you reveal.
Using Box2d just for collision detection(no physics)
(41 posts) (11 voices)-
Posted 2 years ago #
-
@Elik
I'm not to sure if there's a more sophisticated method but maybe you should subclass a sprite that knows how to update the poly positions and shape when the subclass changes.And I haven't really looked into edge detection so I couldn't help there but to do edge/boundary detection you'll need access to the image pixel data. Let's say you have the image data and found the outline points of your image. Then you'll either have to find the convex hull of those points or tessellate the points of your boundary so that it's always convex in order to make box2d polygon.
Should I say "not for the faint of heart"?Doing this at run-time is either too probably too slow or too memory intensive for a game but maybe if you already have the shape outline already stored in a file then reading that to create the shape is pretty easy.
I'll let you dig a little further first through the forum. Post a new thread about these topics if you have a solution or can't find any threads on them.
Posted 2 years ago # -
@Lam
As I'm new to this as mentioned before doing imaging with pipe line processing I do agree with your assessments. the platforms I'm use to is powerful I'm still trying to get use to this environment. Edge detection through skeleton convolution is too intensive but when I feel more knowledgeable about this environment I'll try to explore a redundant alternatives to the issue.
Thank again for helping me and it was nice chat.Posted 2 years ago # -
@Lam
Can you please re-upload your sample to mediafire? The link is no longer active. I'd really like to see it.I'm trying to check if rotated rectangles are in contact, and I've used most of your code, but I think there is a problem with the way I've got the code written. Here is what I have in the init of my HelloWorldScene.mm:
//Set up sprites CCSprite *SpriteA = [CCSprite spriteWithFile:@"icon.png"]; //assume icon is 60X60 [self addChild:SpriteA]; [SpriteA setPosition:ccp(40.0f, 100.0f)]; CCSprite *SpriteB = [CCSprite spriteWithFile:@"icon.png"]; [self addChild:SpriteB]; [SpriteB setPosition:ccp(300.0f, 100.0f)]; [SpriteB setRotation:45.0f]; b2Manifold manifold; b2PolygonShape A,B; //... store the width.height with setBox for the shape region A.SetAsBox(60.0f*PTM_RATIO,60.0f*PTM_RATIO); B.SetAsBox(60.0f*PTM_RATIO,60.0f*PTM_RATIO); //... store the position location and angle of shape A and B into transform with Set. b2Transform transA, transB; transA.Set(b2Vec2(40.0f*PTM_RATIO, 100.0f*PTM_RATIO),0.0f); transB.Set(b2Vec2(200.0f*PTM_RATIO, 100.0f*PTM_RATIO),0.7853f); //0.7853f = 45 degrees b2CollidePolygons(&manifold, &A, transA, &B, transB); if(manifold.pointCount > 0){ NSLog(@"collided"); }In your code you suggested looking at manifold.m_pointCount, but that threw an error. i did find a pointCount, but before calling b2CollidePolygons, the value is 100480, and afterwards it is 2, no matter what I set my box and transform values to...
Any suggestions what I am doing wrong?
Cheers!
Posted 1 year ago # -
Hopefully my dropbox link will always be active. :D
http://dl.dropbox.com/u/271717/SimpleShapeDetection.zip
Unfortunately I tend to get quite busy and it's hard to keep up with the forums. If anyone ever has questions then I generally respond as quickly as I can if you PM me otherwise a post may take weeks/months for me to actually notice =/
I'll let you take a look at the source first and if any problems do pop up (maybe box2d's changed) then I'll see what I can do to help.
Posted 1 year ago # -
@Lam, thank you very much. That code showed me exactly how to do what I wanted. I wasn't able to get your draw method to work in my own project, because it builds the vertices for the box assuming it isn't rotated, which is what I needed the collision detection for :)
Awesome stuff!
Posted 1 year ago # -
Upon reading this thread I though, ahah! Here is what I need, all the convenience of fancy collision detection with whatever style of physics I want to put into my game. I was nearing the point of actually trying out the collisions when I came upon a problem.
A box2d polygon positioned behind a sprite.
A box2d polygon positioned behind a child sprite.Parent sprite rotates around its anchor
Parents Polygon rotates around its centroid
Child sprite rotates around its anchor, around parent anchor
Childs Polygon rotates around its centroid, but not around parents polygons centroidMy box2d experience is very limited.
Are the usual means of making this happen not available without a b2Body?
Do joints play the role that the parent child relationship plays in cocos2d?
Do I really have to restructure everything or write my own translation function for this? (someone please say no to that last one...)I could post some code if it is desired, but I don't think this is a coding error, I'm just lacking a means of getting the parented translation effect.
Posted 1 year ago # -
Here's the fix I used if anyone has the same problem.
http://www.cocos2d-iphone.org/forum/topic/2295?replies=6#post-59921
Posted 1 year ago #
Reply
You must log in to post.