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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:54:08+00:00 2026-06-01T07:54:08+00:00

me need your adwise: i’ve got 2 classes, in first I initialize the object

  • 0

me need your adwise: i’ve got 2 classes, in first I initialize the object of second and i would like to use the function of second class like:

in first class I initialize the object of second

self.keys = [KeyLayer node];
self.keys.position = CGPointMake(-0.f, -0.f);
[self addChild:self.keys z:1]; 

and i want to apply close function of second class to self.keys object like:

[self.keys.sprite self.keys.close]; 

but the it doesn’t work

second class

#import <Foundation/Foundation.h>
#import "cocos2d.h"

@interface KeyLayer : CCLayer  {

    CCLabelTTF *_label;
    CCAction *_actionOpen;
    CCAction *_actionClose;
    CCSprite *_sprite;
    CCAnimation *_animation;

}
@property (nonatomic, retain) CCSprite *sprite;
@property (nonatomic, retain) CCAction *actionOpen;
@property (nonatomic, retain) CCAction *actionClose;
@property (nonatomic, retain) CCAnimation *animation;
@property (nonatomic, retain) CCLabelTTF *label;

+(id) scene;
-(void) open;
-(void) close;
@end

//********************************

#import "KeyLayer.h"
#import "GameLayer.h"

@implementation KeyLayer

@synthesize sprite = _sprite;
@synthesize actionOpen = _actionOpen;
@synthesize actionClose = _actionClose;
@synthesize animation = _animation;
@synthesize label = _label;


+(id) scene
{
    CCScene *scene = [CCScene node];

    return scene;
}

-(id) init
{
    if ((self = [super init]))
    {           
                CGSize screenSize = [[CCDirector sharedDirector] winSize];

        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile: [NSString stringWithFormat:@"key.plist"]];
        CCSpriteBatchNode *animationSpriteSheet = [CCSpriteBatchNode batchNodeWithFile:[NSString stringWithFormat:@"key.png"]];
        [self addChild:animationSpriteSheet];

        //*************************************************

        NSMutableArray *animationFrames = [NSMutableArray array];
        for(int i = 1; i <= 5; ++i) {

                    [animationFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"key_%d.png", i]]];
        }
        _animation = [CCAnimation animationWithFrames:animationFrames delay:0.1f];
        self.sprite = [CCSprite spriteWithSpriteFrameName: [NSString stringWithFormat:@"key_1.png"]]; 
        self.actionOpen = [CCRepeat actionWithAction:[CCAnimate actionWithAnimation:_animation restoreOriginalFrame:NO] times:1];

        //*********************************************

        for(int i = 3; i <= 5; ++i) {

            [animationFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"key_%d.png", i]]];
        }
        _animation = [CCAnimation animationWithFrames:animationFrames delay:0.1f];
        self.sprite = [CCSprite spriteWithSpriteFrameName: [NSString stringWithFormat:@"key_1.png"]]; 
        self.actionClose = [CCRepeat actionWithAction:[CCAnimate actionWithAnimation:_animation restoreOriginalFrame:NO] times:1];

        //*********************************************************  


        self.sprite.anchorPoint = ccp([self.sprite boundingBox].size.width/800, [self.sprite boundingBox].size.height/800);
        self.sprite.position = CGPointMake(-0.f, -0.f); 
        [animationSpriteSheet addChild:self.sprite z:1];


        //****************************************************

        self.label = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"A"] dimensions:CGSizeMake(self.sprite.contentSize.width, self.sprite.contentSize.height) alignment:UITextAlignmentCenter fontName:@"Arial" fontSize:40];
        self.label.anchorPoint = ccp([self.label boundingBox].size.width/800, 0.25);
        self.label.position = CGPointMake(-0.f, -0.f);   
        [self addChild:self.label z:1];

    }
    return self;
}

-(void) openKey
{
    [self.sprite runAction:self.actionOpen];
}
-(void) closeKey
{
    [self.sprite runAction:self.actionClose];
}
- (void) dealloc
{
    self.sprite = nil;
    self.actionOpen = nil;
    self.actionClose = nil;
    self.label=nil;
    [super dealloc];
}
@end
  • 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-01T07:54:10+00:00Added an answer on June 1, 2026 at 7:54 am

    tFirst of all this is not how you call a method on any object :

    [self.keys.sprite self.keys.close]; // even if self.keys.close was defined this is not how you call it
    

    Now, I guess you want to call closeKey on your sprite so it can be easily done by :

    [self.keys closeKey]; // self.keys is your object and closeKey is the method you desire to call on your object. 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need your help. Is it possible to use fancybox as the movie player
I need your expertise once again. I have a java class that searches a
I need your help in creating a java bean to retrieve the first 4
I need your help again. So I have a simple list <ul> <li>First</li> <ul
i need your help in access db i have a table like this ID
Need your help: I want to use Eclipse CDT and QT without creating a
I am working on a project with zend framework and i need your advise
Need your help to get the max of CAP_PRICE based on certain criteria in
I need your help with a short bash script. I have a folder, which
i need your help badly because i cannot solve this problem on my own.

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.