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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:02:43+00:00 2026-06-12T21:02:43+00:00

I am trying to subclass CCSprite but for some reason I can’t seem to

  • 0

I am trying to subclass CCSprite but for some reason I can’t seem to get anything to draw on the screen. I am not a pro with cocos2d so I am open to any suggestions. Here is my code. I have a scene like so:

#import "cocos2d.h"

@class Animation;

@interface HelloWorldLayer : CCLayer
{

}

+(CCScene *) scene;

@end

#import "HelloWorldLayer.h"
#import "Animation.h"
@implementation HelloWorldLayer

+(CCScene *) scene
{
    CCScene *scene = [CCScene node];
    HelloWorldLayer *layer = [HelloWorldLayer node];
    [scene addChild: layer];
    return scene;
}


-(id) init
{
    if( (self=[super init])) {

        CCLOG(@"super init");

        HelloWorldLayer *animation;
        animation = [Animation animation:self];

 }
    return self;
}

- (void) dealloc
{
    [super dealloc];
}
@end

Then I subclass CCSprite like so:

#import <Foundation/Foundation.h>
#import "cocos2d.h"
@class HelloWorldLayer;

@interface Animation : CCSprite {

    HelloWorldLayer     *ivHelloWorld;
}
+ (id) animation:(HelloWorldLayer*) helloWorld;
- (id) initAnimation: (HelloWorldLayer*) helloWorld;
@end

#import "Animation.h"
#import "HelloWorldLayer.h"


@implementation Animation

+ (id) animation:(HelloWorldLayer *) helloWorld{
    CCLOG(@"animation method");
    return [[[self alloc] initAnimation:helloWorld] autorelease];

}

- (id) initAnimation:(HelloWorldLayer *)helloworld {


     CCLOG(@"InitaAnimation method");
    // cache
    CCSpriteFrameCache *cache=[CCSpriteFrameCache sharedSpriteFrameCache];
    [cache addSpriteFramesWithFile:@"FootballAtlas.plist"];

    // frame array
    NSMutableArray *framesArray=[NSMutableArray array];
    for (int i=1; i<60; i++) {
        NSString *frameName=[NSString stringWithFormat:@"Football%d.png", i];
        id frameObject=[cache spriteFrameByName:frameName];
        [framesArray addObject:frameObject];
    }
    CCLOG(@" array count = %i", [framesArray count]);
    // animation object
    id animObject=[CCAnimation animationWithFrames:framesArray delay:0.01];

    // animation action
    id animAction=[CCAnimate actionWithAnimation:animObject restoreOriginalFrame:NO];
    CCRepeatForever *repeat = [CCRepeatForever actionWithAction:animAction];

    id animAction2=[CCAnimate actionWithAnimation:animObject restoreOriginalFrame:NO];
    animAction2=[CCRepeatForever actionWithAction:animAction2];

    // sprite
    CCSprite *bird=[CCSprite spriteWithSpriteFrameName:@"Football0.png"];
    bird.position=ccp(60,160);

    CCSprite *bird2=[CCSprite spriteWithSpriteFrameName:@"Football0.png"];
    bird2.position=ccp(80,160);


    // batchNode
    CCSpriteBatchNode *batchNode=[CCSpriteBatchNode batchNodeWithFile:@"FootballAtlas.png"];
    [self addChild:batchNode];
    [batchNode addChild:bird];
    [batchNode addChild:bird2];

    [bird runAction:repeat];
    [bird2 runAction:animAction2];

    return self;
}
@end

this does not draw anything on the screen, but if I move the animation code to the CClayer then everything shows up fine. What am I doing wrong?

  • 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-12T21:02:45+00:00Added an answer on June 12, 2026 at 9:02 pm

    I figured it out thanks. I was initializing a HelloWorldLayer object where I needed to have an animation object.

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

Sidebar

Related Questions

I'm trying to subclass str , but having some difficulties due to its immutability.
I am simply trying to subclass UIWindow so that I can intercept some notifications.
I am trying to subclass a deque, but can't work out how to set
I'm trying to subclass the built-in file class in Python to add some extra
I am trying to subclass the immutable date class in Python, but I also
I am trying to create a subclass of asp:DropDownList so I can use asp:DdlNoEventValidation
I am trying to highlight multiple lines of a JTextArea subclass (not selected). Although
I'm trying to set up a parent class that extends a subclass, but whenever
I'm trying to get an existing Preference subclass to work that saves a color
I am trying to subclass NSArray , but it crashes the app when trying

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.