Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2012
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Paperjs. setInterval is working very strange

    Hello. My question is about paperjs.
    I want make the circle and after every 1 second, x position this circle
    increases with 5 px.
    This is my code:


    Code:
    var x = 20; 
    var center = new Point(x,20); 
    var radius = 10; 
    var myCircle = new Path.Circle(center,radius); 
    myCircle.fillColor = '#090'; 
    function positionChange () { 
            x = x + 5; 
            myCircle.position = new Point(x,20); 
    } 
    
    setInterval(positionChange,1000);

    This code works very strange, that is, if mouse is move, position
    circle is changed, but if mouse is delayed, circle position not change
    o_O.
    Please tell me why?
    Last edited by VIPStephan; 05-07-2012 at 10:10 PM.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,455
    Thanks
    0
    Thanked 632 Times in 622 Posts
    That function is just changing the position of the circle. It isn't redrawing the circle on the screen. So you only see the circle move when you perform an action that triggers the code to redraw the circle.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New Coder
    Join Date
    May 2012
    Posts
    16
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    That function is just changing the position of the circle.
    Yes, I wanted to do exactly that, that is, i want make circle and change its x position automatically.

    In my code, circle posotion is changed if I move a mouse, if mouse is stopped, the circle position is not changed.
    And I can not understood, why is this happening? why not changed circle position, when mouse is stopped ?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •