unexpexced jump of graphics and delay displaying

Member
Posts: 164
Joined: 2010.10
Post: #1
i have two problems perhaps binded to the same reason:
1) i have a touchesEnded event that performs this:

Code:
if ([self pawnCanMoveHere:i]) {
       [self iniMenu:1];
       //return;      
       [many calculation here...]
    }

initMenu performs only loading from cache some textures:

Code:
-(void)initMenu:(int)tipo{
        CCTextureCache *st=[CCTextureCache sharedTextureCache];
        switch (tipo) {
            case -1:
                menuSxUp=[CCSprite spriteWithFile:@"menuSxUpRosso.png"];
                menuSxDw=[CCSprite spriteWithFile:@"menuSxDwRosso.png"];
                menuSxAlone=[CCSprite spriteWithFile:@"menuSxAlone.png"];//è uguale per tutti SX
                menuSxDw.anchorPoint=ccp(0,0);
                menuSxDw.position=ccp(0,0);
                menuSxDw.scale=0.5*globalScaleFactor;
                
                menuSxUp.anchorPoint=ccp(0,0);
                menuSxUp.position=ccp(0,128/2);
                menuSxUp.scale=0.5*globalScaleFactor;
                
                menuSxAlone.anchorPoint=ccp(0,0);
                menuSxAlone.position=ccp(128/2,64/2);
                menuSxAlone.scale=0.5*globalScaleFactor;
                
                
                menuDxUp=[CCSprite spriteWithFile:@"menuDxUpRosso.png"];
                menuDxDw=[CCSprite spriteWithFile:@"menuDxDwRosso.png"];
                menuDxAlone=[CCSprite spriteWithFile:@"menuDxAloneRosso.png"];
                menuDxDw.anchorPoint=ccp(0,0);
                menuDxDw.position=ccp(832/2,0);
                menuDxDw.scale=0.5*globalScaleFactor;
                
                menuDxUp.anchorPoint=ccp(0,0);
                menuDxUp.position=ccp(832/2,128/2);
                menuDxUp.scale=0.5*globalScaleFactor;
                
                menuDxAlone.anchorPoint=ccp(0,0);
                menuDxAlone.position=ccp(800/2,0);
                menuDxAlone.scale=0.5*globalScaleFactor;
                
            case 0://rosso
                [menuSxUp setTexture:[st textureForKey:@"menuSxUpRosso.png"]];
                [menuSxDw setTexture:[st textureForKey:@"menuSxDwRosso.png"]];
                [menuDxUp setTexture:[st textureForKey:@"menuDxUpRosso.png"]];
                [menuDxDw setTexture:[st textureForKey:@"menuDxDwRosso.png"]];
                [menuDxAlone setTexture:[st textureForKey:@"menuDxAloneRosso.png"]];
                break;
            case 1:    
                [menuSxUp setTexture:[st textureForKey:@"menuSxUpNero.png"]];
                [menuSxDw setTexture:[st textureForKey:@"menuSxDwNero.png"]];
                [menuDxUp setTexture:[st textureForKey:@"menuDxUpNero.png"]];
                [menuDxDw setTexture:[st textureForKey:@"menuDxDwNero.png"]];
                [menuDxAlone setTexture:[st textureForKey:@"menuDxAloneNero.png"]];
                break;
            case 2:    
                [menuSxUp setTexture:[st textureForKey:@"menuSxUpBianco.png"]];
                [menuSxDw setTexture:[st textureForKey:@"menuSxDwBianco.png"]];
                [menuDxUp setTexture:[st textureForKey:@"menuDxUpBianco.png"]];
                [menuDxDw setTexture:[st textureForKey:@"menuDxDwBianco.png"]];
                [menuDxAlone setTexture:[st textureForKey:@"menuDxAloneBianco.png"]];
                break;
            default:
                break;
        }
    }

what happens is: if i leave things like here, the texture changes after many calculation (even if the instruction is before!)
if i uncomment //return; display is immediate...
whY???
how can i force redisplay before that calculation"


perhaps the same problem i have here...
in short: i have a function that calls runAction to have a sequence of animations, in case 8, i have to make many calculations.
what happens is that the action in case 8 is a jump instead of a move like the acion is started before calculations...

Code:
-(void)refreshDonnePositions2{
        CGPoint p;
        switch (actionSequence) {
            case -1:
                [scaleLayer runAction:[CCSequence actionOne:[CCScaleTo actionWithDuration:0.5 scale:1] two:[CCCallFuncN actionWithTarget:self selector:@selector(refreshDonnePositions2)]]];
                animateMovesSeq=0;
                break;
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
                p=[panLayer convertToWorldSpace:vittima[actionSequence].position];
                p.x=(panLayer.position.x+(240-p.x));
                p.y=(panLayer.position.y+(160-p.y));  
                [panLayer runAction:[CCSequence actionOne:[CCMoveTo actionWithDuration:0.5 position:p] two:[CCCallFuncN actionWithTarget:self selector:@selector(animateDonneMoves)]]];
                break;
            case 5:
                animateMovesSeq=0;
            case 6:
            case 7:
                if(jackTurn==0){
                    p=[panLayer convertToWorldSpace:fakeVittima[actionSequence-5].position];
                    p.x=(panLayer.position.x+(240-p.x));
                    p.y=(panLayer.position.y+(160-p.y));  
                    [panLayer runAction:[CCSequence actionOne:[CCMoveTo actionWithDuration:0.5 position:p] two:[CCCallFuncN actionWithTarget:self selector:@selector(animateSventurateMoves)]]];
                }
                break;
            case 8:
                animateMovesSeq=0;
                [self inizializzaMenu:1];
                //[self chiVaEDove:[self caselleVicinoAlleDonne]];
                [self scegliCasellaVicinoAllaDonnaDaProteggere];
                [self decisioniPoliziotti];
            case 9:
            case 10:
            case 11:
            case 12:
                p=[panLayer convertToWorldSpace:polizia[actionSequence-8].position];
                p.x=(panLayer.position.x+(240-p.x));
                p.y=(panLayer.position.y+(160-p.y));  
                [panLayer runAction:[CCSequence actionOne:[CCMoveTo actionWithDuration:0.5 position:p] two:[CCCallFuncN actionWithTarget:self selector:@selector(animatePoliziottiMoves)]]];
                //[CCCallFuncN actionWithTarget:self selector: @selector(muoviPol)]
                break;
            case 13:
                animateMovesSeq=0;
                //[self chiVaEDove:[self caselleVicinoAlleDonne]];
                [self scegliCasellaPolFakeVicinoAllaDonnaDaProteggere];
                [self decisioniFakePoliziotti];
            case 14:
                p=[panLayer convertToWorldSpace:fakePoliceman[actionSequence-14].position];
                p.x=(panLayer.position.x+(240-p.x));
                p.y=(panLayer.position.y+(160-p.y));  
                [panLayer runAction:[CCSequence actionOne:[CCMoveTo actionWithDuration:0.5 position:p] two:[CCCallFuncN actionWithTarget:self selector:@selector(animateFakePoliziottiMoves)]]];
                //[CCCallFuncN actionWithTarget:self selector: @selector(muoviPol)]
                break;
            case 15:
                [self interfaceMenuKiller];
                break;
            default:
                break;
        }
        actionSequence++;
    }

could be a problem of thread?
how can i make this thing work?
thanks
Quote this message in a reply
Member
Posts: 49
Joined: 2011.08
Post: #2
You have a loop issue. If you are using multiple loops or actions and they switch back and forth, create a true / false value. If something is true, run loop 1, else run loop 2.
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #3
...sorry i have not understood...
for the first problem the skeleton of the program is:
1) player touch menu
2) change texture of the menu
3) enemy think what is the next move (and there is a loop)
4) animate decision made (and there is a sequence of actions)
but i obtain:
1) player touch menu
2)
3) enemy think what is the next move
4) change texture of the menu & animate decision made

if i change so:
1) player touch menu
2) change texture of the menu
3) return
texture change istantaly
thanks
Quote this message in a reply
Member
Posts: 104
Joined: 2002.04
Post: #4
My guess is that you are running into threading issue. When you get a touch event, it is running on the main loop. If you try and do all of the calculation on the main loop, then it won't give up control to the drawing routines until the calculations are finished.
I think you'll likely need to refactor the calculations into another loop. So, when you receive the touch event, change the texture, and dispatch a new thread to do the calculations. Once the calculation thread is done, it kicks off the animation of the decision made.
Quote this message in a reply
Member
Posts: 164
Joined: 2010.10
Post: #5
sounds an interesting solution, searching on internet i found this method:
Code:
[NSThread detachNewThreadSelector:@selector(aMethod:) toTarget:[MyObject class] withObject:nil];
- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg on NSObject
or NSOperation...
i'll try something
thanks
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  jump preview StealthyCoin 1 2,769 Mar 7, 2008 10:25 AM
Last Post: StealthyCoin
  Displaying graphics on a second monitor Bert 5 3,926 May 12, 2005 09:23 AM
Last Post: Ingemar
  Holding Spacebar To Jump Nick 9 5,183 Aug 21, 2004 05:47 AM
Last Post: PowerMacX
  Removing delay until key repeat hyperutila 4 4,055 Jan 16, 2004 01:36 PM
Last Post: FCCovett