This site requires JavaScript, please enable it in your browser!
Greenfoot back
ronald
ronald wrote ...

2019/7/19

drawOval move

1
2
ronald ronald

2019/7/19

#
 int i = 0;
    
    public DrawOval()
    {
        GreenfootImage gfim = new GreenfootImage(70,70);
        gfim.setColor(Color.BLACK);
        gfim.drawOval(0,0,70,70);
        gfim.fillOval(0,0,70,70);
        this.setImage(gfim);
        
        
    }
    
    
    
    
    public void act()
    {
    {
        for(int i = 1; i<10; i++)
        
        { 
        move(1);
        }
    }     
    }
} 
I try to move drawOval a dozen times with for loops Thank you
danpost danpost

2019/7/19

#
Lines 20 thru 24 is equivalent to:
move(10);
Your drawOval actor (black ball) should move across the entire screen from left to right in about 1 second (assuming a world width of 600).
ronald ronald

2019/7/19

#
what i try to do is to move the black ball 5 times or 10 times automatically from the original black ball without clicking 5 times or 10 times on the run button
danpost danpost

2019/7/19

#
ronald wrote...
what i try to do is to move the black ball 5 times or 10 times automatically from the original black ball without clicking 5 times or 10 times on the run button
Don't you mean the "Act" button? The "Run" button turns into a "Pause" button when you click it (and vice versa); so, it would take twice as many clicks than times executed.
ronald ronald

2019/7/19

#
I mean I click once on the run button and the black ball starts 5 times or 10 times from the original black ball or is the starting point of the black ball
danpost danpost

2019/7/19

#
ronald wrote...
I mean I click once on the run button and the black ball starts 5 times or 10 times from the original black ball or is the starting point of the black ball
Okay. I think want you want can be achieved by changing your line 1 above to:
int i = 10;
with the following act method:
public void act()
{
    if (i > 0)
    {
        move(1);
        i--;
    }
}
This will only work once for each ball object.
ronald ronald

2019/7/19

#
it does not work
danpost danpost

2019/7/19

#
ronald wrote...
it does not work
Show the entire class code for the black ball.
ronald ronald

2019/7/19

#
int i = 10;
    
    public DrawOval()
    {
        GreenfootImage gfim = new GreenfootImage(70,70);
        gfim.setColor(Color.BLACK);
        gfim.drawOval(0,0,70,70);
        gfim.fillOval(0,0,70,70);
        this.setImage(gfim);
        
        
    }
    
    public void act()
    {
        if (i>10)
        {
            move(1);
            i--;
        }
    }
}
if I put 20 as int variable and move (3), it will move a little but once with the run button and 10 times by pressing the act button what interests me is to move 10 times with the run button by clicking once as if the black ball was duplicated 10 times
danpost danpost

2019/7/19

#
Line 16 must remain as:
if (i > 0)
I am not sure what you are trying to do ("duplicated 10 times"?). Please explain in full detail.
ronald ronald

2019/7/19

#
I will try to explain, for example I click once on the run button, the black ball moves automatically 5 or 10 times from left to right from the starting black ball instead of clicking 5 times or 10, we al impression that the black ball is duplicated 5 or 10 times from the original black ball, it is as if it was a programmed loop that stops after 5 or 10 times by clicking once on the button, it always moves from of the black ball of origin or departure which gives the impression that it is duplicated x times that's what I was trying to do with for loop, it's just an idea, maybe it's feasible or not, maybe I'm wrong
danpost danpost

2019/7/19

#
If it is like you are leaving a permanent trail behind, then I suggest you draw its image onto the world background after each move. For ease, you can make use of by BgInk actor support class. You add it to the world where you would put the actor and tell it to draw (or apply) the actor's image there. You can find it in my Clock w/BgInk Support Class scenario. It is well documented, so you should be able to follow how to use the objects created from the class. Be aware that once an image is draw, the BgInk object drawing it automatically removes itself from the world.
danpost danpost

2019/7/19

#
danpost wrote...
You can find it in my Clock w/BgInk Support Class scenario.
I have noticed it is not currently downloadable. Will update it soon.
danpost danpost

2019/7/19

#
I could not readily find that scenario. I updated a different one with source that contains the class.
ronald ronald

2019/7/20

#
I do not know what your scenario looks like, except that the trace behind is the same as the object that sends it, must i look
There are more replies on the next page.
1
2