Note that there are some explanatory texts on larger screens.

plurals
  1. POSingleton function not retaining value
    primarykey
    data
    text
    <p>I'll preface this question by saying that I am a total noob when it comes to Objective-C. So please, be patient with my question. :)</p> <p>So here is my issue. I am basically allowing the user to 'rub out' an image by using alpha blending and such, and then converting the created texture to a CCSprite. I am then able to store the CCSprite in a function within my singleton class. Like so:</p> <pre><code>erasedTextureSprite = [CCSprite spriteWithTexture:darknessLayer.sprite.texture]; [[MySingleton sharedMySingleton] setRevealTexture:erasedTextureSprite]; </code></pre> <p>Here is the <code>setRevealTexture</code> &amp; <code>getRevealTexture</code> function as well as the revealTexture variable initialisation in my <code>MySingleton.h</code> file:</p> <pre><code>@interface MySingleton : NSObject { CCSprite *revealTexture; } ... -(void) setRevealTexture: (CCSprite *) texture; -(CCSprite *) getRevealTexture; </code></pre> <p>And here are both functions in my <code>MySingleton.m</code> file:</p> <pre><code>-(void) setRevealTexture: (CCSprite *) texture { NSLog(@"set reveal texture."); revealTexture = texture; NSLog(@"%f", [revealTexture boundingBox].size.width); } -(CCSprite *) getRevealTexture { NSLog(@"got reveal texture."); NSLog(@"%f", revealTexture.contentSize.width); return revealTexture; } </code></pre> <p>If I set the reveal texture, and then get it right away, it seems to return the sprite correctly. However, if I set the texture and then transition to another scene, it seems to lose it's value, and throws me an error when I try and call the <code>getRevealTexture</code> function.</p> <p><em><strong>Question</em></strong>: <strong>Why is my function not retaining it's value when I transition between scenes?</strong></p> <p>If any more clarification is needed please let me know!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload