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

2019/6/30

drawline

1
2
ronald ronald

2019/6/30

#
I know that you have to use getbackground () drawline for a straight line with the world class if I understand it but I do not know how to start it Thank you for your help
danpost danpost

2019/6/30

#
The method names are getBackground and drawLine (with B and L in uppercase letters).
ronald ronald

2019/6/30

#
I'll write better next time, for drawLine, use setColor, otherwise it's white, I do not understand, I thought I would see a black line without setColor must always use color, what
danpost danpost

2019/6/30

#
ronald wrote...
I'll write better next time, for drawLine, use setColor, otherwise it's white, I do not understand, I thought I would see a black line without setColor must always use color, what
Any GreenfootImage object you create by giving dimensions of the image will draw BLACK without having to specify. The setting of the color WHITE for the background of the world is done by greenfoot. I have had no reason to test other images (those created by other constructors), so I cannot say anything about them at the moment (would be easy to check, however).
ronald ronald

2019/7/1

#
 getBackground().drawPolygon(int [] {5,10,15,20},int [] {25,30,35,40},5);
this line of code is good or not, it does not work yet i followed the API
danpost danpost

2019/7/1

#
ronald wrote...
<< Code Omitted >> this line of code is good or not, it does not work yet i followed the API
You only have 4 points listed in the arrays -- not 5. Also, both arrays are new.
ronald ronald

2019/7/1

#
yes quite, I just realized
ronald ronald

2019/7/1

#
why new ?
danpost danpost

2019/7/1

#
ronald wrote...
why new ?
Because an array is an object that needs to be created.
ronald ronald

2019/7/1

#
ok
ronald ronald

2019/7/1

#
the last time you gave me the code that moves the object with the cursor, my question is how to connect for example, your code with the cursor with drawLine or other, with that I can draw lines with the cursor, I do not know not if you understand me. for example, there are a lot of code methods, I am trying to understand how to connect two code methods or should I rewrite the code method with two code methods it's hard to connect once you have all the formulas, I'm not trying to create anything but just understanding I do not know if I made myself clear Thank you for your help
danpost danpost

2019/7/1

#
ronald wrote...
the last time you gave me the code that moves the object with the cursor, my question is how to connect for example, your code with the cursor with drawLine or other, with that I can draw lines with the cursor,
I would make use of the position/movement of the object following the cursor. Before it moves AND after you know how it is going to move, you could use something like this (dx and dy are the distances to be moved horizontally and vertically);
getWorld().getBackground().drawLine(getX(), getY(), getX()+dx, getY()+dy);
ronald ronald

2019/7/2

#
if(Greenfoot.mouseMoved(null))
        {
            MouseInfo mouseInfo = Greenfoot.getMouseInfo();
            setLocation(mouseInfo.getX(), mouseInfo.getY());
        }
        
how to link this code above with this code below, i try to understand how to do Thank you for your help
getWorld().getBackground().drawLine(getX(), getY(), getX()+dx, getY()+dy);
Super_Hippo Super_Hippo

2019/7/2

#
if (Greenfoot.mouseMoved(null))
{
    MouseInfo mouseInfo = Greenfoot.getMouseInfo();
    int x=getX(), y=getY(), dx=mouseInfo.getX()-x, dy=mouseInfo.getY()-y;
    getWorld().getBackground().drawLine(x, y, x+dx, y+dy);
    setLocation(x+dx, y+dy);
}
ronald ronald

2019/7/2

#
thank you, I'll never think something like this, finally, i have a lot to learn i added setColor in myWorld and it works on the other hand, I added also public void drawLine in Actor, I do not know if it's worth adding it, it works without also with public void act
There are more replies on the next page.
1
2