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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:24:15+00:00 2026-06-10T06:24:15+00:00

I’m new to Objective-C and C in general. I’ve been looking around and I

  • 0

I’m new to Objective-C and C in general. I’ve been looking around and I couldn’t find the solution to this issue. Any help would be appreciated.

I have the following global variables

CCSprite* BackgroundImage;
CCSprite* BackgroundGhost;
CCSprite* Globe;
CCSprite* Logo;

in my init I call a function and pass the global variables as parameters.

if(_ourDevice == iPad)
   {

       [self CustomCodeSetAssetForIpad:BackgroundImage ghost:BackgroundGhost TheGlobe:Globe AndTheLogo:Logo];


   }

Here is the code for CustomCodeSetAssetForIpad:

-(void) CustomCodeSetAssetForIpad:(CCSprite*) _Background ghost:(CCSprite*) _BackgroundGhosts TheGlobe:(CCSprite*)_Globes AndTheLogo:(CCSprite*) _Logos
{
    _Background = [CCSprite spriteWithFile:@"1028-768-sunray.png"];
    _BackgroundGhosts = [CCSprite spriteWithFile:@"1028-768-sunray.png"];
    _Globes = [CCSprite spriteWithFile:@"BigGlobe.png"];
    _Logos  = [CCSprite spriteWithFile:@"DefaultLogo.png"];

    [_BackgroundGhosts setAnchorPoint:CGPointMake(0.5, 0)];
    [_BackgroundGhosts setScale:2];
    [_BackgroundGhosts setOpacity:120];
    //[BackgroundGhost setPosition: CGPointMake(BackgroundGhost.position.x, BackgroundGhost.position.y-500)];

    [_BackgroundGhosts setPosition:CGPointMake([[CCDirector sharedDirector]winSize].width/2, -100)];

    [_Globes setAnchorPoint:CGPointMake(0.5, 0.5)];
    [_Globes setScale:0.7];
    [_Globes setPosition:CGPointMake([[CCDirector sharedDirector]winSize].width/2, -260)];



    [_Logos setPosition:CGPointMake([self CenterOfTheScreen].x, [[CCDirector sharedDirector]winSize].height-[[CCDirector sharedDirector]winSize].height*0.2)]; 
    [_Logos setScale:0.05];


}

The first few lines instantiate the global variables that were passed. However when the function is done, the reference to those objects are lost. I thought when you pass a pointer to a function, as the object is instantiated, it would retain its reference to the instantiated object. Am I missing something here?

  • 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-10T06:24:17+00:00Added an answer on June 10, 2026 at 6:24 am

    Ah… Variables of type classname * are effectively references to instances of that class. So in your case, _Background is an instance reference passed in as an argument to your function. If you are trying to return multiple results from a function (via pointers), your arguments should really of type classname **, which is a pointer to a reference.

    So the calling code would look like this:

    CCSprite * background = nil ;
    CCSprite * ghosts = nil ;
    CCSprite * globes = nil ;
    CCSprite * logos = nil ;
    

    [ self customCodeSetAssetForIpad:&background ghosts:&ghosts globes:&globes logos:&logos ] ;

    And your method looks like this:

    -(void)customCodeSetAssetForIPad:(CCSprite**)background ghosts:(CCSprite**)backgroundhosts globe:globes logos:(CCSprite**)logos
    {
        *background = [CCSprite spriteWithFile:@"1028-768-sunray.png"];
        // ... the rest of your code ...
    }
    

    Also, I took the liberty of making your method name and variable names more objective-c like (methods and variables begin with lowercase letters)

    EDIT: I’d personally structure it like this:

    //
    // World... global things go in here
    //
    
    @interface World
    
    @property ( nonatomic, readonly, strong ) CCSprite * background ;
    
    +(id)theWorld // accessor to get the global world object
    
    @end
    
    @implementation World
    @synthesize CCSprite * background = _background ;
    
    static World * __theWorld = nil ; // global variable to hold our shared global World instance
    
    +(void)load
    {
        // when this class is loaded, create our global world object
        __theWorld = [ [ [ self class ] alloc ] init ] ;
    }
    
    +(id)theWorld
    {
        return __theWorld ;
    }
    
    // return the background sprite, creating it if it hasn't be created yet
    -(CCSprite*)background
    {
        if ( !_background) { _background = [ CCSprite spriteWithFile:[CCSprite spriteWithFile:@"1028-768-sunray.png"] ; }
        return _background ;
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words

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.