Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9005119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:03:55+00:00 2026-06-16T01:03:55+00:00

I have written code for a game in which some birds are flying. I

  • 0

I have written code for a game in which some birds are flying. I created array of CCSprite and added them on Scene. Now it assign a scheduler to each bird object for moving in random direction in screen. All are working. Now i am getting trouble in getting collision in birds.

i am trying to run a CCARRAY_FOREACH loop on array but its giving error.

 0xC0000005: Access violation reading location 0xfeeefeee.

Please help me how i can get get collision detection in array element while they are moving. updateCollison method is not executing.

My Code is:

#include "HelloWorldScene.h"

using namespace cocos2d;

CCScene* HelloWorld::scene()
{
    CCScene * scene = NULL;
    do 
    {
        // 'scene' is an autorelease object
        scene = CCScene::create();
        CC_BREAK_IF(! scene);

        // 'layer' is an autorelease object
        HelloWorld *layer = HelloWorld::create();
        CC_BREAK_IF(! layer);

        // add layer as a child to scene
        scene->addChild(layer);
    } while (0);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //srand(time(NULL));
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    birds = CCArray::create();
    for(int j = 0; j<5; j++){
        CCSprite *bird = CCSprite::create("twitter_square.png");
        bird->setTag(j);
        int max = rand() % 480;
        int min = rand() % 320;
        bird->setPosition(ccp(max, min));
        this->addChild(bird);
        birds->addObject(bird);
        bird->schedule( schedule_selector(HelloWorld::moveBird), 5.0 );
bird->schedule( schedule_selector(HelloWorld::updateCollison), 5.0 );
    }

    return true;
}

void HelloWorld::menuCloseCallback(CCObject* pSender)
{
    CCDirector::sharedDirector()->end();
}


void HelloWorld::moveBird(float dt)
{
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    int max = rand() % (int)size.width;
    int min = rand() % (int)size.height;
    CCActionInterval*  actionTo = CCMoveTo::actionWithDuration(5, ccp(max,min));
    this->runAction(actionTo);
}

void HelloWorld::updateCollison(float dt)
{
    CCObject *obj;
    for(int i=0; i < birds->count(); i++)
    {
        CCLOG("$$$$$$$$$$$$$$$$$$$$$$$");
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:03:56+00:00Added an answer on June 16, 2026 at 1:03 am

    It’s better to do things in one update function …for example make one update in that call MoveBird Function which will contain your moving bird code

    Secondly now call check Collision function

    void update (float dt) {
    
    MoveBird();     // Move how many birds you want to move 
    CheckCollision();
    
    }
    

    Now how to check collision of your birds

    In your collision function forLoop your birds Array check

    if(mBirdsArray[i]->boundingBox().containsPoint(mBirdsArray[j]->getPosition()))
    

    and vice versa …

    I hope this will work .. .there maybe better logic than this ..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written some code in JSP to download .docx files which is hosted
I have a two year old game code which was completely written in cpp
I have written some code that loads an XML document using an XmlDocument object
I have written some code for displaying a drop down list, but the code
I have some code written in Ruby 1.9.2 patch level 136 and I'm have
I have a small Flash game which is written with AS3. My game sends
I have written a checkers game model which has a Board object that holds
I have an application which is mostly native code written in C: Simon Tatham's
Occasionally I'll have a situation where I've written some code and, based on its
I have written a game (I'll give it the name Gamer) in which I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.