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

2019/5/30

Referencing methods from other actors

LegitTeddyBears LegitTeddyBears

2019/5/30

#
Right now I'm working on a small game where I can shoot projectiles out of my actor to destroy other actors. I originally tried to use addObject(new (nameofclass), this.x, this.y) but it says I can't do that (method can't find symbol (nameofclass), int, int). So my other other idea was to create a method in my world and call that method whenever I wanted to spawn thy bullet but getworld() gets the world class not my actual world. So I'm not sure what to do. Clearly I'm doing it wrong, what should I be doing? Edit: To specify my main goal is to spawn the projectile on the player.
danpost danpost

2019/5/30

#
LegitTeddyBears wrote...
getworld() gets the world class not my actual world.
That is incorrect. The getWorld method return the World object that the actor is currently in (not the World class).
I originally tried to use addObject(new (nameofclass), this.x, this.y) but it says I can't do that (method can't find symbol (nameofclass), int, int).
In your original attempt, did you try getWorld().addObject( ...?
LegitTeddyBears LegitTeddyBears

2019/5/30

#
I just tried this, now it says that the x in this.x isn't public and therfore can't be cannot be accessed from outside the package. Edit: I replaced this.x with getX() and it conpiled! Thank you
You need to login to post a reply.