SKSpriteNode think's it is (null) after initialization












0















I have a SKSpriteNode that I initialized with this code



//viewDidLoad
bullet = [SKSpriteNode spriteNodeWithImageNamed:@"missile2"];
bullet.xScale = 1;
bullet.yScale = 1;
bullet.position = CGPointMake(67, 148);
bullet.zRotation = M_PI;
[self addChild:bullet];


In a previous question, I asked why I can't set it's position, we determined it was because the sprite was null, when I logged NSLog(@"bullet is %@",bullet);



Here is a link to that question.



Sprite position not working in Objective C, Xcode



My question is, why does Xcode think this sprite is null when I am initializing it in viewDidLoad?










share|improve this question

























  • Where is the bullet variable declared (not where it is initialized)?

    – Gliderman
    May 12 '16 at 1:57













  • It is declared in the .h file with SKSpriteNode *bullet;

    – user3386154
    May 12 '16 at 3:39


















0















I have a SKSpriteNode that I initialized with this code



//viewDidLoad
bullet = [SKSpriteNode spriteNodeWithImageNamed:@"missile2"];
bullet.xScale = 1;
bullet.yScale = 1;
bullet.position = CGPointMake(67, 148);
bullet.zRotation = M_PI;
[self addChild:bullet];


In a previous question, I asked why I can't set it's position, we determined it was because the sprite was null, when I logged NSLog(@"bullet is %@",bullet);



Here is a link to that question.



Sprite position not working in Objective C, Xcode



My question is, why does Xcode think this sprite is null when I am initializing it in viewDidLoad?










share|improve this question

























  • Where is the bullet variable declared (not where it is initialized)?

    – Gliderman
    May 12 '16 at 1:57













  • It is declared in the .h file with SKSpriteNode *bullet;

    – user3386154
    May 12 '16 at 3:39
















0












0








0








I have a SKSpriteNode that I initialized with this code



//viewDidLoad
bullet = [SKSpriteNode spriteNodeWithImageNamed:@"missile2"];
bullet.xScale = 1;
bullet.yScale = 1;
bullet.position = CGPointMake(67, 148);
bullet.zRotation = M_PI;
[self addChild:bullet];


In a previous question, I asked why I can't set it's position, we determined it was because the sprite was null, when I logged NSLog(@"bullet is %@",bullet);



Here is a link to that question.



Sprite position not working in Objective C, Xcode



My question is, why does Xcode think this sprite is null when I am initializing it in viewDidLoad?










share|improve this question
















I have a SKSpriteNode that I initialized with this code



//viewDidLoad
bullet = [SKSpriteNode spriteNodeWithImageNamed:@"missile2"];
bullet.xScale = 1;
bullet.yScale = 1;
bullet.position = CGPointMake(67, 148);
bullet.zRotation = M_PI;
[self addChild:bullet];


In a previous question, I asked why I can't set it's position, we determined it was because the sprite was null, when I logged NSLog(@"bullet is %@",bullet);



Here is a link to that question.



Sprite position not working in Objective C, Xcode



My question is, why does Xcode think this sprite is null when I am initializing it in viewDidLoad?







objective-c null sprite-kit skspritenode






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 3:09









Cœur

18.5k9110148




18.5k9110148










asked May 11 '16 at 22:37









user3386154user3386154

549




549













  • Where is the bullet variable declared (not where it is initialized)?

    – Gliderman
    May 12 '16 at 1:57













  • It is declared in the .h file with SKSpriteNode *bullet;

    – user3386154
    May 12 '16 at 3:39





















  • Where is the bullet variable declared (not where it is initialized)?

    – Gliderman
    May 12 '16 at 1:57













  • It is declared in the .h file with SKSpriteNode *bullet;

    – user3386154
    May 12 '16 at 3:39



















Where is the bullet variable declared (not where it is initialized)?

– Gliderman
May 12 '16 at 1:57







Where is the bullet variable declared (not where it is initialized)?

– Gliderman
May 12 '16 at 1:57















It is declared in the .h file with SKSpriteNode *bullet;

– user3386154
May 12 '16 at 3:39







It is declared in the .h file with SKSpriteNode *bullet;

– user3386154
May 12 '16 at 3:39














1 Answer
1






active

oldest

votes


















0














I guess you are just invoking



NSLog(@"bullet is %@",bullet);


before the bullet property is initialized.



Maybe you put the NSLog line inside the init right? That would be an explanation since init does happen before viewDidLoad.






share|improve this answer


























  • I don't completely understand what happened, but I got it to work. It turns out I was calling a method from another file the wrong way, I must have been initializing it again, because all my variables were set to 0. I called the method a different way and it worked.

    – user3386154
    May 17 '16 at 17:18











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37174417%2fskspritenode-thinks-it-is-null-after-initialization%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I guess you are just invoking



NSLog(@"bullet is %@",bullet);


before the bullet property is initialized.



Maybe you put the NSLog line inside the init right? That would be an explanation since init does happen before viewDidLoad.






share|improve this answer


























  • I don't completely understand what happened, but I got it to work. It turns out I was calling a method from another file the wrong way, I must have been initializing it again, because all my variables were set to 0. I called the method a different way and it worked.

    – user3386154
    May 17 '16 at 17:18
















0














I guess you are just invoking



NSLog(@"bullet is %@",bullet);


before the bullet property is initialized.



Maybe you put the NSLog line inside the init right? That would be an explanation since init does happen before viewDidLoad.






share|improve this answer


























  • I don't completely understand what happened, but I got it to work. It turns out I was calling a method from another file the wrong way, I must have been initializing it again, because all my variables were set to 0. I called the method a different way and it worked.

    – user3386154
    May 17 '16 at 17:18














0












0








0







I guess you are just invoking



NSLog(@"bullet is %@",bullet);


before the bullet property is initialized.



Maybe you put the NSLog line inside the init right? That would be an explanation since init does happen before viewDidLoad.






share|improve this answer















I guess you are just invoking



NSLog(@"bullet is %@",bullet);


before the bullet property is initialized.



Maybe you put the NSLog line inside the init right? That would be an explanation since init does happen before viewDidLoad.







share|improve this answer














share|improve this answer



share|improve this answer








edited May 14 '16 at 18:16

























answered May 14 '16 at 18:10









Luca AngelettiLuca Angeletti

41.2k571116




41.2k571116













  • I don't completely understand what happened, but I got it to work. It turns out I was calling a method from another file the wrong way, I must have been initializing it again, because all my variables were set to 0. I called the method a different way and it worked.

    – user3386154
    May 17 '16 at 17:18



















  • I don't completely understand what happened, but I got it to work. It turns out I was calling a method from another file the wrong way, I must have been initializing it again, because all my variables were set to 0. I called the method a different way and it worked.

    – user3386154
    May 17 '16 at 17:18

















I don't completely understand what happened, but I got it to work. It turns out I was calling a method from another file the wrong way, I must have been initializing it again, because all my variables were set to 0. I called the method a different way and it worked.

– user3386154
May 17 '16 at 17:18





I don't completely understand what happened, but I got it to work. It turns out I was calling a method from another file the wrong way, I must have been initializing it again, because all my variables were set to 0. I called the method a different way and it worked.

– user3386154
May 17 '16 at 17:18




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37174417%2fskspritenode-thinks-it-is-null-after-initialization%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Hercules Kyvelos

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud