1 Reply Latest reply on Jul 23, 2013 6:41 AM by kglad

    Create movement like snake for iOS

    SteCard

      Hello,

      i have this function to create a snake like movement

       

      stage.addEventListener(Event.ENTER_FRAME, function()

      {

                head.x = mouseX;

        head.y = mouseY;

        tail.graphics.clear();

        tail.graphics.lineStyle(3, 0x005e00);

        tail.graphics.moveTo(head.x, head.y);

                nodes[0] = {x:head.x, y:head.y};

                for (i=1; i<tail_nodes - 1; i++)

                {

                          var rotation = Math.atan2(nodes[i].y - nodes[i - 1].y, nodes[i].x - nodes[i - 1].x);

                          var pos_x = nodes[i - 1].x + tail_len * Math.cos(rotation);

                          var pos_y = nodes[i - 1].y + tail_len * Math.sin(rotation);

                          nodes[i] = {x:pos_x, y:pos_y};

        tail.graphics.lineTo(pos_x, pos_y);

       

                }

      });

       

      this work perfectly on computer and browser but when i export the ipa file for testing on my ipad it works jerkily (seems like low framerate).

       

      What is wrong? the event.Enter_Frame? any suggestion to create a similar effect?

       

      Thanks,

      Stefano