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

2014/6/7

Method cannot be applied

Hutanoi Hutanoi

2014/6/7

#
Hello, i need some help :/ pls have understanding if my mistake are very heavy, i just started working with greenfoot. I want an Actor (Brocken) make divide hisself into 2 smaller "Brockens" when he gets hit by the "Kugel" public class Brocken extends Actor { public int size; public Brocken() { size = 50; } public void setSize(int size) { this.size = size; GreenfootImage image = getImage(); image.scale(size, size); } public void act() { treffen(); } public void treffen() { Actor a = this.getOneIntersectingObject(Kugel.class); if( a != null) { this.getWorld().removeObject(a); zerbrechen(); } } public void zerbrechen() { int r = getRotation() + Greenfoot.getRandomNumber(45); Brocken a1 = new Brocken(); Brocken a2 = new Brocken(); getWorld().addObject(a1, getX(), getY()); getWorld().addObject(a2, getX(), getY()); a1.setSize(size/1.6); a2.setSize(size/1.6); a1.setRotation(r+60); a2.setRotation(r-60); a1.move(); a2.move(); getWorld().removeObject(this); } } It says: method setSize in class Brocken cannot be applied to given types; required: int; found: double; reason: actual argument double cannot be converted to int by method invocation conversion Any ideas?
danpost danpost

2014/6/7

#
Try changing 'size/1.6' to 'size*5/8' (using int values).
lordhershey lordhershey

2014/6/7

#
When ever you divide by a power of 2 you can se a right shift. It is a trick that was widely used when division was considered too expensive of an operation... Waaayyyy back before machines ran in the hundred MHz ranges...
danpost danpost

2014/6/7

#
@lordhershey, I still have several working machines of that nature. I have one -- it's an Compac Presario laptop with no hard drive; it has one 3-1/2 in disk drive and a top-side ball mouse (your fingers roll the ball to move the mouse).
Hutanoi Hutanoi

2014/6/8

#
wow, it worked, thank you :) Unfortunately now i have another problem with the same code... method move in class greenfoot.actor cannot be applied to given types; required: int; found: no arguments; reason: actual and formal argument lists differ in length the line a1.move(); is marked red. Why doesnt it work? :/
danpost danpost

2014/6/8

#
The 'move' method supplied in the Actor class require an argument that informs it how far to move (a number put in the parenthesis). It must be an 'int' value.
lordhershey lordhershey

2014/6/8

#
@danpost I still have a Tandy 1000 SX , the thing still works, I was thinking of pulling it out a doing some basic programming on it for kicks. It has no mouse, I did upgrade it several times, put a 20 Meg Hardcard in it, ram up to 640K, replaced 1 of the 5 1/4 inch drives with a 3 1/2 720k drive. Only thing I did not do was put extended memory in.
You need to login to post a reply.