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

2014/8/1

Need Some Help With Variables and Actors

bluefoot135 bluefoot135

2014/8/1

#
Hi I'm new to Greenfoot and find it fascinating. I've already created a small and simple game with it. I was trying to improve it when I stumbled upon a problem. Actually several problems. First of all, I don't know how to create a variable that is referencing an actor. I've searched the discussion for a few hours and all the popular users type "this" instead of the actual script in which to write this so I was unable to help myself. Another problem I have is similar to this. I can't find the correct way to make two actors delete themselves upon contact. My game is similar to Galaga, but a lot simpler. When the bullet hits the enemy, the enemy disappears, but the bullet is able to fly on, mowing down hoards of enemies at a time. I wish to make the bullet disappear along with the enemy upon collision. I tried the first thing that came to my mind, which was having both actors delete the other, but only the enemy is deleted in the end. I would appreciate help on both of these problems I'm having. Thanks
danpost danpost

2014/8/2

#
For you first problem, refer to the java tutorial page on Objects (the second section is on declaring a variable to refer to an object. For you second problem, the page on 'this' keyword is what you need to refer to. It would be best to remove the 'other' object before removing 'this' object from the world.
You need to login to post a reply.