Hi, I started programming with Greenfoot some weeks ago and constantly have some difficulties, until now, i succeeded in resolving most of them, but now... I'm completely blocked... so I explain:
I'm trying to add an Object at the coordinates (x and y). The point is that my x is given by an addition of two numbers (two doubles I think) and Greenfoot is unable to compile (it says: incompatible types: possible lossy conversion from double to int)
Here's the part of the code that goes wrong
the part that is in bold is what's marked in red by Greenfoot
Can someone help me with this please? :)
PS: Sorry for my bad english, it's not my native language^^
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | private void laser() { MouseInfo mouse = Greenfoot.getMouseInfo(); int xMouse = mouse.getX(); int yMouse = mouse.getY(); double xThis = this .getExactX(); double yThis = this .getExactY(); double dx = xMouse-xThis; double dy = yMouse-yThis; double length = Math.sqrt(dx*dx+dy*dy); double xLength = dx/length; double yLength = dy/length; if (Greenfoot.mousePressed( null )) { for ( int i= 0 ; i<length; i++) { Weapon1 weapon1 = new Weapon1(); getWorld().addObject(weapon1, this .getX()+[b]i*xLength[/b], this .getExactY()+[b]i*yLength[/b]); } } } |