need a solution

  • rashasalah
    Likes 0

    Problem Description
     var listener1 = cc.eventManager.addListener({
                          event:cc.EventListener.MOUSE,
                               onMouseDown: function(event) {
                                if (event.getButton() == cc.EventMouse.BUTTON_LEFT){ 
                                         if(right.isSelected()) { 
                                                  x1=a;   y1=b;  LR+=x1;
                                               actions.push(cc.MoveBy.create(0.5, cc.p(x1,y1))); 
                                               score();  
                                                 
                                                 } 
                                else if(left.isSelected()){
                                                  x1=-a;    y1=b;  LR+=x1;
                                                actions.push(cc.MoveBy.create(0.5, cc.p(x1,y1))); 
                                                score();   
                                                   
                                                }
                                else if(down.isSelected()) {
                                                   x1=0;  y1=-a;  UD+=y1;
                                                actions.push(cc.MoveBy.create(0.5, cc.p(x1,y1)));  
                                                score();      
                                                 
                                                }  
                                else if(up.isSelected()) {if(updown>0)  {
                                                  x1=0;   y1=a;  UD+=y1;
                                                 actions.push(cc.MoveBy.create(0.5, cc.p(x1,y1)));
                                                score();      
                                                     } 
    
                                                 }
                                else if(playItem.isSelected())    { 
                                      runFunction(); 
                                     playItem.setEnabled(false); 
                                     menu.setEnabled(false);   
                                      }
                                else if(replayItem.isSelected())  { 
                                     replayAction();     
                                      }    
                                else if(pauseItem.isSelected())  {  
                                      ++fl;  
                                      pauseResume();  
                                        }                
                         }     }
                }, this);  
    
                  var changeFunction = function(){
                           if(LR==(100-(px1*50))&&UD==(py1*-50)){
                          setTimeout(function(){
                                   var scoreText =cc.LabelTTF.create("CONGRATULATIONS","Impact","50");
                                   scoreText.setPosition(pos);
                                   scoreText.color = cc.color(255,215,0);
                                   var rotate = cc.RotateBy.create(1,360);
                                   scoreText.runAction(rotate);
                                   this_.addChild(scoreText);
                              },2500);  
                           }
                      }
                 var runFunction = function(){
                          var seq = new cc.Sequence.create(actions,cc.callFunc(changeFunction(), this));   
                          nimo.runAction( seq); 
                          if(flag1){    dory.runAction(dory_action);    }
                          if(flag2){    oct.runAction(oct_action);      }
                          if(flag3){    parent.runAction(parent_action);  
                              }
        
                         }
    

    i want to make the actions in the actions[] run one after one like the same in sequence action in the runfunction(), because when i try to run it with for loop the actions tun fast tillit make a curve not a line how can that happen , itis my graduated project in my colledge so i really want a certain answer in cocos2d js , please i tried many times and nothing happened correctly

  • Sonar Systems admin
    Likes 0

    What happens without a loop?

  • rashasalah
    Likes 0

    the motion become like a curve not in a line segment for example : in 4*4 grid i need to move right one place and down one place so with loop it become curved line not straight and found error which : this.target is null !! 

  • Sonar Systems admin
    Likes 0

    Are you doing the horizontal and vertical movement at the same time?

  • rashasalah
    Likes 0

    no every turn in the for loop one action only is run in the array of the actions saved 

  • rashasalah
    Likes 0

    can i contact any developer here ,please ?

    it is a graduation project and i really need a help to overcome this problem 

    thanks 

    if not give me a sloution , if yes i will be very glad

  • Sonar Systems admin
    Likes 0

    Have you tried a sequence?


    This reply has been verified.
  • rashasalah
    Likes 0

    yes i have tried it but i have a problem with it i run it in a called function with another actions the senario is : 

    nimo spirte try to move on grid i.e 3*3 so he move 2 towards right  where dory spirte  is located and 2 downwards in the grid where nimo’s dad is found 

    i want nimo when go to the same position of any other spirte as dory or dad to be disappered i made it by fadeout after that when went to the dad’s postions which i make it nimo’s goal a text appered like : congratulation , level 1 complete 

    when i make a sequence of actions of nimo moves in array actions which named “actions ”in the snip code i have posted in previous replay and begin to run sequence after this actions  ,

    i make a conditions if flags is true as he in the dory or dad position to be disappered and if itis goal to appear congruts text ,  

    but thats not what happen while running : all of this instructions run in parallel why? i don’t now!! , so i tried to make action by action to prevent this parallel running actions but the probelm i have asked about it first happen  

    this is my senario kid’s game i need a solution please , thanks 

    my part of code which make this problem 

    actions array ----   playmenuitem : calls (run function) --- run function : calls (change function ) --- change function : congratulation text

     var listener1 = cc.eventManager.addListener({
                          event:cc.EventListener.MOUSE,
                               onMouseDown: function(event) {
                                if (event.getButton() == cc.EventMouse.BUTTON_LEFT){ 
                                         if(right.isSelected()) { if (c<2) {
                                               ++c;   m1=1;  cre();   x1=a;   y1=b;  LR+=x1;
                                               actions.push(cc.MoveBy.create(0.5, cc.p(x1,y1))); 
                                               score();  
                                                  }
                                                 } 
                                else if(left.isSelected()){if(c>0) {
                                                --c;  m2=1;  cre();  x1=-a;    y1=b;  LR+=x1;
                                                actions.push(cc.MoveBy.create(0.5, cc.p(x1,y1))); 
                                                score();   
                                                 }    
                                                }
                                else if(down.isSelected()) {if(updown<2) {
                                                ++updown;   m3=1;  cre();   x1=0;  y1=-a;  UD+=y1;
                                                actions.push(cc.MoveBy.create(0.5, cc.p(x1,y1)));  
                                                score();      
                                                 }
                                                }  
                                else if(up.isSelected()) {if(updown>0)  {
                                                --updown;m4=1;cre();    x1=0;   y1=a;  UD+=y1;
                                                 actions.push(cc.MoveBy.create(0.5, cc.p(x1,y1)));
                                                score();      
                                                     } 
    
                                                 }
                                else if(playItem.isSelected())    {   
                                     runFunction(); 
                                     playItem.setEnabled(false); 
                                     menu.setEnabled(false);   
                                      }
    
    
    var changeFunction = function(){
                          if(LR==(100-(px1*50))&&UD==(py1*-50)){
                          setTimeout(function(){
                                   var scoreText =cc.LabelTTF.create("CONGRATULATIONS","Impact","50");
                                   scoreText.setPosition(pos);
                                   scoreText.color = cc.color(255,215,0);
                                   var rotate = cc.RotateBy.create(1,360);
                                   scoreText.runAction(rotate);
                                   this_.addChild(scoreText);
                              },2500);  
                           }
                      }
                
    
                var runFunction = function(){
    
                          var seq = new cc.Sequence.create(actions, cc.callFunc(changeFunction(), this));   
                          nimo.runAction( seq); 
                          if(flag1){    dory.runAction(dory_action);    }
                          if(flag2){    oct.runAction(oct_action);      }
                          if(flag3){    parent.runAction(parent_action);  
                              }
        
                         }

     


  • Sonar Systems admin
    Likes 0

    Try settings the actions in the sequence without an array.

  • rashasalah
    Likes 0

    the same thing is happen no change

    how can i solve that ?

    can i upload the project file  here and check it for me ?

  • rashasalah
    Likes 0

    my main problem is the call of the “change function” in the code shared ,itis run in parallel of the run sequence and that is not true i have to wait until be in the goal place and that thing not happen 

    so from the senario i have commented it here before how can i manage the movement of nimo inside the grid ?

Login to reply