Hi,
I have 2 classes which this question relates to: frames and hero. I want to stop the hero from moving when the frame is shown on the screen. so far I have this for the frames class:
In the act method of the Hero I have this but not sure where I have gone wrong retuning if frameActive value. The code is as follows:
Any suggestions?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Message here. * * @author (your name) * @version (a version number or a date) */ public class Frames extends Tiles { public boolean frameActive; public Frames(String selection) { this .selection = selection; this .directory = "Frames/" ; this .frameActive = true ; if (selection == "type1" ) setImage(directory + "type1.png" ); else if (selection == "type2" ) setImage(directory + "type2.png" ); } public void act() { if (getWorld().getObjects(Text. class ).size() == 0 && Greenfoot.isKeyDown( "enter" )) { this .frameActive = false ; getWorld().removeObject( this ); } } public boolean getFrameActive() { return frameActive; } } |
1 2 3 4 5 6 7 8 | public void act() { if (((Frames) getWorld().getObjects(Frames. class ).get( 0 )).getFrameActive() == false ) { checkKeys(); } mapSpecificBoundaries(); } |