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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:42:16+00:00 2026-05-23T12:42:16+00:00

I have a CCLayer class where I create an animated sprite that is the

  • 0

I have a CCLayer class where I create an animated sprite that is the “hero” for the game. Now, I am trying to create multiple enemies for him to fight, and I’m having trouble. I want to create a class called “Enemy” that holds everything relevant to the enemy, and just create multiple instances of that class for all my enemies. How do I go about doing this?

Here’s the class I have so far (where i create teh hero, called “_bear”.

#import "FightGame.h"
#import "SneakyJoystick.h"
#import "SneakyJoystickSkinnedBase.h"
#import "ColoredCircleSprite.h"
#import "CCTouchDispatcher.h"
#import "GManager.h"

CCSprite *player;
BOOL _moving, _crouched, _jumping, _actionTouch, _maxJump, _leftJumping, _rightJumping,         _punching, _kicking, _touchSet;
int startX, startY;

@implementation FightGame

@synthesize bear = _bear;
@synthesize jumpAction = _jumpAction;
@synthesize walkAction = _walkAction;
@synthesize punchAction = _punchAction;
@synthesize kickAction = _kickAction;
@synthesize crouchAction = _crouchAction;
@synthesize currentTouch;

+(id) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];

// 'layer' is an autorelease object.
FightGame *layer = [FightGame node];

// add layer as a child to scene
[scene addChild: layer];

// return the scene
return scene;
}

// on "init" you need to initialize your instance
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init] )) {
    /*player = [CCSprite spriteWithFile: @"Person1.png"];
    player.position = ccp( 50, 100 );
    [self addChild:player]; */

    //bools
    _maxJump = FALSE;
    _jumping = FALSE;
    _leftJumping = FALSE;
    _rightJumping = FALSE;
    _touchSet = FALSE;


    //Animated Bear
    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Fighter.plist"];

    CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode 
                    batchNodeWithFile:@"Fighter.png"];
    [self addChild:spriteSheet];

    //load frames
    NSMutableArray *walkAnimFrames = [NSMutableArray array];
    for(int i = 1; i <= 6; ++i) {
        [walkAnimFrames addObject:
         [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
          [NSString stringWithFormat:@"walk%i.png", i]]];
    }

    NSMutableArray *punchAnimFrames = [NSMutableArray array];
    for(int i = 1; i <= 2; ++i) {
        [punchAnimFrames addObject:
         [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
          [NSString stringWithFormat:@"punch%i.png", i]]];
    }

    NSMutableArray *jumpAnimFrames = [NSMutableArray array];
    for(int i = 1; i <= 3; ++i) {
        [jumpAnimFrames addObject:
         [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
          [NSString stringWithFormat:@"jump%i.png", i]]];
    }

    NSMutableArray *kickAnimFrames = [NSMutableArray array];
    for(int i = 1; i <= 3; ++i) {
        [kickAnimFrames addObject:
         [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
          [NSString stringWithFormat:@"kick%i.png", i]]];
    }

    //create animation
    CCAnimation *walkAnim = [CCAnimation 
                             animationWithFrames:walkAnimFrames delay:0.1f];
    CCAnimation *punchAnim = [CCAnimation 
                             animationWithFrames:punchAnimFrames delay:0.1f];
    CCAnimation *jumpAnim = [CCAnimation 
                             animationWithFrames:jumpAnimFrames delay:0.5f];
    CCAnimation *kickAnim = [CCAnimation 
                             animationWithFrames:kickAnimFrames delay:0.1f];


    CGSize winSize = [CCDirector sharedDirector].winSize;
    self.bear = [CCSprite spriteWithSpriteFrameName:@"walk1.png"];        
    _bear.position = ccp(winSize.width/2, winSize.height/2);

    //creating the actions
    self.walkAction = [CCRepeatForever actionWithAction:
                       [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];

    self.punchAction = [CCRepeat actionWithAction:[CCAnimate actionWithAnimation:punchAnim] times:1];

    self.jumpAction = [CCRepeat actionWithAction:[CCAnimate actionWithAnimation:jumpAnim] times:1];

    self.kickAction = [CCRepeat actionWithAction:[CCAnimate actionWithAnimation:kickAnim] times:1];

    [spriteSheet addChild:_bear];


    //end animated bear, start joystick
    SneakyJoystickSkinnedBase *leftJoy = [[[SneakyJoystickSkinnedBase alloc] init] autorelease];
    leftJoy.position = ccp(60,60);
    leftJoy.backgroundSprite = [ColoredCircleSprite circleWithColor:ccc4(105, 105, 105, 200) radius:55];
    leftJoy.thumbSprite = [ColoredCircleSprite circleWithColor:ccc4(255, 0, 0, 200) radius:25];
    leftJoy.joystick = [[SneakyJoystick alloc] initWithRect:CGRectMake(0,0,128,128)];
    leftJoystick = [leftJoy.joystick retain];
    [self addChild:leftJoy];
    [self schedule:@selector(nextFrame:)];
    self.isTouchEnabled = YES;
}
return self;
}
  • 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-05-23T12:42:16+00:00Added an answer on May 23, 2026 at 12:42 pm

    I could just give you the answer on this but that is useless. You need to crawl before you can run. Go to RayWenderlich.com and do at least some of his Cocos2D tutorials. You will get yourself up to speed quickly enough.

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

Sidebar

Related Questions

I have a cclayer class with invisible button that is the size of the
I have three classes I am trying to link together for my game. I
I have a class that takes an NSString as a parameter, uses Core Text
class token { private: char m_chIcon; //actual ascii char that shows up for this
I have a CALayer with some image contents. When a button touched, I want
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you used VS.NET Architect Edition's Application and System diagrams to start designing 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.