×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    8

    Drawing many particles in a loop doesn't work.

    Here is an example of my problem, this code does draw:
    Code:
    public static void paint(Graphics g, Ball2 balls, int startX,int imWidth, int endY, Image img, Object ths ){        
            for(int i = 0;i<balls.getBallPositionsArr().length/2;i++){                                 
                 //g.setColor (0xffffcc);
                 //g.fillRoundRect( (int)(balls.getX(i) - balls.getRadius())-2, (int)(balls.getY(i) - balls.getRadius())-2, (int) balls.getRadius()+4, (int) balls.getRadius()+4,1,1);                                         
                 g.setColor (0xffffcc); 
                 g.fillRect(20, 20, 50, 10);
            }
                 g.setColor (0xffffcc); 
                 g.fillRect(20, 20, 50, 10);                          
    }
    while this doesn't:
    Code:
    public static void paint(Graphics g, Ball2 balls, int startX,int imWidth, int endY, Image img, Object ths ){        
            for(int i = 0;i<balls.getBallPositionsArr().length/2;i++){                                 
                 //g.setColor (0xffffcc);
                 //g.fillRoundRect( (int)(balls.getX(i) - balls.getRadius())-2, (int)(balls.getY(i) - balls.getRadius())-2, (int) balls.getRadius()+4, (int) balls.getRadius()+4,1,1);                                         
                 g.setColor (0xffffcc); 
                 g.fillRect(20, 20, 50, 10);
            }                   
    }


    Why the last piece of code, which shall draw to "g" in a loop doesn't do what's expected? How can I fix it?
    In Java SE both work.
    Last edited by vitali.pom; 2011-11-01 at 10:54.

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2011
    Posts
    555

    Re: Drawing many particles in a loop doesn't work.

    Hi,

    Can you try to get the value of

    balls.getBallPositionsArr().length/2

    when you run your program?
    It could be that for some reason, this expression is evaluated to 0 and that could force your program to skip entirely the "for" loop.
    Last edited by skalogir; 2011-11-01 at 16:51.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    8

    Re: Drawing many particles in a loop doesn't work.

    Indeed, the value was 0.
    Thank you.

Similar Threads

  1. module "Qt.labs.particles" is not installed on N8
    By chintandave_er in forum [Archived] Qt Quick
    Replies: 7
    Last Post: 2011-01-28, 07:25
  2. samegame "Qt.labs.particles" is not installed
    By fg313071405 in forum [Archived] Qt General ( Qt技术)
    Replies: 2
    Last Post: 2010-12-21, 03:25
  3. Form.append() doesn't work inside a while loop
    By balajei in forum Mobile Java General
    Replies: 2
    Last Post: 2010-01-22, 12:57
  4. exiting a loop / loop and thread.
    By adamzieba in forum Mobile Java General
    Replies: 1
    Last Post: 2007-08-04, 15:15
  5. Drawing text in heavily loop
    By hieungtr in forum Symbian User Interface
    Replies: 4
    Last Post: 2007-05-20, 01:29

Posting Permissions

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