This project is read-only.

How To Match Sprites Speed on Collision Detection (COCOS-2dx) ??

Topics: Performance, Physics
Nov 8, 2013 at 7:48 AM
I am working on Game where a Bird Drop Heart from Top of the Screen, whereas Catching Birds are Moving All over the Screen. So what Is Happening is When a Top Bird Drops the Heart , Catcher Birds'll Caught it and take it out. I am getting the following problem :

-> I'd successfully detect collision between heart and Catcher Birds , after that I copied the Catcher Bird position to Heart, apply an action on Heart to Move it Along the X-axis.

-> But the problem I am getting is : Speed Mismatch of Catcher Bird and the Moving Heart on Catcher Bird hand.

-> Also my Catcher Birds followed two Types of random Actions : CCMoveTo and ccBezierConfig. So I also would like to know how to COPY catcher's bird Action on Heart (that is on catcher bird hand) , so that Catcher Bird Move Synchronously with caught Heart.

-> I'd followed this code to detect collision and Move Catcher Bird with Caught Heart :

private void Update_Heart_Birds_Intersect(float timer)
        List<CCSprite> targetToDelete = new List<CCSprite>();
        List<CCSprite> heartsToDelete = new List<CCSprite>();

        for (int i = 0; i < _hearts.Count; i++)  // count heart thrown by Main_Upper_Angel
            CCSprite projectile = _hearts[i];                

            CCRect projectileRect = new CCRect(projectile.position.x - projectile.contentSize.width / 2,
                projectile.position.y - projectile.contentSize.height / 2,
                projectile.contentSize.width, projectile.contentSize.height);

            //foreach (CCSprite angel in _angelscatcher)
            foreach (Birds_Type angel in _angelscatcher)   //bird type class extends CCSprite to Calc. ActualMoveDuration
                CCRect targetRect = new CCRect(angel.position.x - angel.contentSize.width / 2,
                    angel.position.y - angel.contentSize.height / 2,

                if (CCRect.CCRectIntersetsRect(projectileRect, targetRect))                 

                    System.Diagnostics.Debug.WriteLine("Intersection Occurs-------------------");  //intersect works perfect

                    CCSprite angel_demo_heart = CCSprite.spriteWithFile(@"Images/heart"); //create a heart to hold on Catcher's Bird hand

                    angel_demo_heart.position = angel.position; //catcher bird position copied to a heart

                    angel_demo_heart.tag = 3;

                    CCActionInterval actionTo = CCMoveTo.actionWithDuration(angel.actualMoveDuration, new CCPoint(0, angel.position.y));

                    angel_demo_heart.runAction(CCSequence.actions(CCEaseBounce.actionWithAction(actionTo), CCCallFuncN.actionWithTarget(this, DropHeartFinished)));

                    addChild(angel_demo_heart); // move heart with catcher's angel


            foreach (CCSprite target in targetToDelete)
                _angelscatcher.Remove(target);   //remove prev. intersection position                   

            if (targetToDelete.Count > 0)   // if intersect occurs, then add item in heart list to remove

        foreach (CCSprite projectile in heartsToDelete)
            _hearts.Remove(projectile);  //remove prev. intersection position
            this.removeChild(projectile, true);
-> Please look on Code and Suggest a Useful Solution !!


Nov 11, 2013 at 4:06 PM
Pardeep, you are using cocos2d-x-for-xna, which we do not support anylonger.

Please use the cocos2d-xna source from github ( ...
Nov 14, 2013 at 12:59 PM
Hi totallyevil,

I solved my this problem . I need to ask you is there is any cocos2d version for silverlight , because we cannot use controls like listbox in XNA projects.
Also there is website in which a chinese guy edit Cocos2d libraries here :

We can create a Hybrid silverlight-xna project but cocos 2d doesnot support in Silverlight.
Please provide a useful link / code to accomplish my task. Any help'll be appreciated.

Pardeep Sharma
Nov 16, 2013 at 10:50 PM
Hello, someone once posted some code on the forums in the c# forum some code for doing a Silverlight container that hosted cocos2d-x-for-xna.
Nov 22, 2013 at 11:59 AM
hi totallyevil,

I appreciate your reply in this post , can you please provide one-step ahead of it , by providing a direct link of Silverlight container that hosted cocos2d-x-for-xna .
I want to use Cocos2Dx for Silverlight + xna , provide a little more help in this would be really helpful for me.

Dec 7, 2013 at 7:06 PM
hello Pardeep, you can find the original post on the C# forums.