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 8338685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:40:18+00:00 2026-06-09T04:40:18+00:00

I have a Balloon class (see this ) that inherits from CCSprite . I

  • 0

I have a Balloon class (see this) that inherits from CCSprite. I have given it properties like balloonSpeed and balloonStrength. I seem to be having problems in it, though.

What I want to do is that when I make an instance of the Balloon class, I want it to do the following:

  • Give it a texture (a PNG file of a balloon).
  • Set properties like balloonSpeed and balloonStrength.
  • Add actions to make it move and accept touch input.

When the object is touched, I want to:

  • Count if # of taps = balloonStrength. if so, destroy Balloon.

I have done a simpler version of this where a Balloon object is destroyed when it is touched. I want to apply OOP and custom classes here but I can’t seem to get the right way of doing it.

Thanks in advance.

  • 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-09T04:40:19+00:00Added an answer on June 9, 2026 at 4:40 am

    then the h file should looks like below:

    #include "cocos2d.h"
    using namespace cocos2d;
    
    class Balloon : public cocos2d::CCSprite, public CCTargetedTouchDelegate {
    public:
    float balloonSpeed;
    int balloonStrength;
    int numberOfTaps;
    virtual void onEnter();
    virtual void onExit();
    virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);
    virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);
    virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
    }; 
    

    and in your touch method:

    bool Balloon::ccTouchBegan(CCTouch* touch, CCEvent* event){
        CCPoint touchLocation = this->getParent()->convertTouchToNodeSpace(touch);
        if (CCRect::CCRectContainsPoint(this->boundingBox(), touchLocation)) {
            this->numberOfTaps++;
            if(this->balloonStrength == this->numberOfTaps){ 
                this->removeFromParentAndCleanup(true);
            }
        }
    
        return true;
    }
    

    you can use it after you add the blueBalloon as a child of a layer or node as below:

    blueBalloon->balloonSpeed = 2.0f;
    blueBalloon->numberOfTaps = 0;
    blueBalloon->balloonStrength = 5;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called Textures that use holds some data like this //Textures.h
I have a MapView with Overlays like this: public class MyMapActivity extends MapActivity {
I have a custom view that I would like to create from a resource
I have this game where balloons are coming from bottom and player has to
have written this little class, which generates a UUID every time an object of
I have some code that basically inflates a 'balloon' through 15 or so stages
I have a balloonGameViewController.h and another class I made called balloon.h I want to
Say you have a view that is a circle or a balloon and you
I have some code that pops up a balloon tip. It works on Vista
I have a function that shows a balloon tray in Windows it has a

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.