ios - Method can't be used within Switch statement? -



ios - Method can't be used within Switch statement? -

how come can't utilize scenewithsize: within switch statement? if create object of new game scene outside switch case works fine? i\m switching game scenes depending on spritenode user selected. why happening , there alternative method i'm trying do?

-(void)touchesbegan:(nsset *)touches withevent:(uievent *)event { /* called when touch begins */ uitouch *touch = [touches anyobject]; cgpoint location = [touch locationinnode:self]; sknode *node = [self nodeatpoint:location]; nslog(@"level selected: %@", node.name); int x = [node.name intvalue]; switch (x) { case 1: // if move code outside switch statement works? levelone *newscene = [levelone scenewithsize:self.size]; // here expected look error? //[self.view presentscene:newscene transition:[sktransition doorsopenverticalwithduration:1]]; break; default: break; } }

it's not because of method call, it's because can't start case variable declaration. have wrap whole block in curly braces, this:

switch (x) { case 1: { // if move code outside switch statement works? levelone *newscene = [levelone scenewithsize:self.size]; // here expected look error? //[self.view presentscene:newscene transition:[sktransition doorsopenverticalwithduration:1]]; break; } default: break; }

ios switch-statement

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -