13 Replies Latest reply on Sep 25, 2014 3:17 PM by kglad

    Smooth movement of Background

    andersonlipa

      Hi can anyone help me, I want to know what action to have a result like this site http://www.radicaltesta.com/index_d.php

      I can do everything but leave the smoothest navigation, that's my jam. If anyone can give me the action of smooth motion I would be very happy for the help. Thank you

        • 1. Re: Smooth movement of Background
          kglad Adobe Community Professional & MVP

          var easeSpeed:Number = .5;

           

          your_bg.cacheAsBitmap=true;

          this.addEventListener(Event.ENTER_FRAME,f);

          function f(e:Event):void){

          your_bg.x = easeSpeed*your_bg.x+(1-easeSpeed)*mouseX;

          your_bg.y = easeSpeed*your_bg.y+(1-easeSpeed)*mouseY;

          }

          • 2. Re: Smooth movement of Background
            andersonlipa Level 1

            Hi friend its action seems to work. I want to add your command line in this code. Could you help me because I can not add your command within my event, if you can write a new command line fixing problems I would be very happy.

            .......................................................................................... .......................................................................................... .

             

            import flash.events.MouseEvent;

             

             

            addEventListener(MouseEvent.MOUSE_MOVE, Bg_mov);

             

             

            function Bg_mov(e:MouseEvent):void{

             

             

             

              var distX:Number = stage.stageWidth - bg.width;

              var distY:Number = stage.stageHeight - bg.height;

             

              var quantX:Number = mouseX / stage.stageWidth;

              var quantY:Number = mouseY / stage.stageHeight;

             

              var posX:Number = distX * quantX;

              var posY:Number = distY * quantY;

             

             

              bg.x = posX;

              bg.y = posY;

             

             

            }

            • 3. Re: Smooth movement of Background
              kglad Adobe Community Professional & MVP

              that code won't yield smooth movement.

               

              use the code i suggested and adjust the speed parament (between 0 and 1) to control the speed of momement.

              • 4. Re: Smooth movement of Background
                andersonlipa Level 1

                Its action seems to work but yet always starts at x0 and y0, also seems to leave so the stage background. Is there any way to leave as in the example Mentioned site? In the example objects interact with the bg and remain within the stage, also when the mouse is moved the opposite way will move as it goes to +x and-x. You can pass me this action? Please help me.

                 

                . RADICAL TESTA - ESTRATEGIA .

                • 5. Re: Smooth movement of Background
                  kglad Adobe Community Professional & MVP

                  yes, define your parameters:

                   

                  var leftLimit:int

                  var rightLimit:int

                  var upLimit:int

                  var downLimit:int

                  var easeSpeed:Number;

                   

                  paramF(your_bg,'xMove',leftLimit,stage.stageWidth,right,rightLimit,0);

                  paramF(your_bg,'yMove',upLimiit,stage.stageHeight,downLimit,0);

                   

                   

                   

                   

                  your_bg.cacheAsBitmap=true;

                  this.addEventListener(Event.ENTER_FRAME,f);

                  function f(e:Event):void){

                  your_bg.x = easeSpeed*your_bg.x+(1-easeSpeed)*(your_bg.xMove.m*mouseX+your_bg.xMove.b);

                  your_bg.y = easeSpeed*your_bg.y+(1-easeSpeed)*(your_bg.yMove.m*mouseY+your_bg.yMove.b);

                  }

                   

                  function paramF(mc:MovieClip,s:String,x1:Number,y1:Number,x2:Number:y2:Number):void{

                  mc[s].m=(y1-y2)/(x1-x2);

                  mc[s]=b=y1-mc[s].m*x1;

                  }

                  • 6. Re: Smooth movement of Background
                    andersonlipa Level 1

                    Thank you for your effort to help me but I need you to help me writing all the action or command des its beginning, because I'm new to Flash am having difficulties. If you can do this I will be grateful. Thank you

                    • 7. Re: Smooth movement of Background
                      kglad Adobe Community Professional & MVP

                      i did.

                      • 8. Re: Smooth movement of Background
                        andersonlipa Level 1

                        I did as mentioned, I have the following errors:

                         

                         

                         

                         

                        Scene 1, Layer 'Action', Frame 1, Line 15 column 25 1158: Syntax error: missing left brace ({) before the function body.

                        Scene 1, Layer 'Action', Frame 1, Line 20 column 68 1084: Syntax error: expecting colon before rightparen.

                        • 9. Re: Smooth movement of Background
                          kglad Adobe Community Professional & MVP

                          use:

                           

                           

                           

                          yes, define your parameters:

                           

                          var leftLimit:int

                          var rightLimit:int

                          var upLimit:int

                          var downLimit:int

                          var easeSpeed:Number;

                           

                          paramF(your_bg,'xMove',leftLimit,stage.stageWidth,right,rightLimit,0);

                          paramF(your_bg,'yMove',upLimiit,stage.stageHeight,downLimit,0);

                           

                           

                           

                           

                          your_bg.cacheAsBitmap=true;

                          this.addEventListener(Event.ENTER_FRAME,f);

                          function f(e:Event):void{

                          your_bg.x = easeSpeed*your_bg.x+(1-easeSpeed)*(your_bg.xMove.m*mouseX+your_bg.xMove.b);

                          your_bg.y = easeSpeed*your_bg.y+(1-easeSpeed)*(your_bg.yMove.m*mouseY+your_bg.yMove.b);

                          }

                           

                          function paramF(mc:MovieClip,s:String,x1:Number,y1:Number,x2:Number,y2:Number):void{

                          mc[s].m=(y1-y2)/(x1-x2);

                          mc[s]=b=y1-mc[s].m*x1;

                          }

                          • 10. Re: Smooth movement of Background
                            andersonlipa Level 1

                            Thank you for your effort in helping me, but I'm having a lot of mistakes here compiler.

                            erro.jpg

                            • 11. Re: Smooth movement of Background
                              kglad Adobe Community Professional & MVP

                              that should be:

                               

                              kglad wrote:

                               

                              use:

                               

                               

                               

                              yes, define your parameters:

                               

                              var leftLimit:int

                              var rightLimit:int

                              var upLimit:int

                              var downLimit:int

                              var easeSpeed:Number;

                               

                              paramF(your_bg,'xMove',leftLimit,stage.stageWidth,rightLimit,0);

                              paramF(your_bg,'yMove',upLimiit,stage.stageHeight,downLimit,0);

                               

                               

                               

                               

                              your_bg.cacheAsBitmap=true;

                              this.addEventListener(Event.ENTER_FRAME,f);

                              function f(e:Event):void{

                              your_bg.x = easeSpeed*your_bg.x+(1-easeSpeed)*(your_bg.xMove.m*mouseX+your_bg.xMove.b);

                              your_bg.y = easeSpeed*your_bg.y+(1-easeSpeed)*(your_bg.yMove.m*mouseY+your_bg.yMove.b);

                              }

                               

                              function paramF(mc:MovieClip,s:String,x1:Number,y1:Number,x2:Number,y2:Number):void{

                              mc[s].m=(y1-y2)/(x1-x2);

                              mc[s].b=y1-mc[s].m*x1;

                              }

                              p.s. you need to define those parameters.

                              • 12. Re: Smooth movement of Background
                                andersonlipa Level 1

                                You could write the complete action for me with the parameters and everything. My Bg has the name "bg"

                                • 13. Re: Smooth movement of Background
                                  kglad Adobe Community Professional & MVP

                                  the appropriate parameters depends on your reg points and personal preferences.  there's no easy way to determine those via a forum.

                                   

                                  if you want to hire me to do this for you, send me a personal message.