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

2014/2/22

Class, interface or enum expected error

Aspire_Seven Aspire_Seven

2014/2/22

#
I am making a video game scroll world and so far i have typed this: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class ScrollWorld extends World { int baseX=0; // 'bgi' stands for Background Image GreeenfootImage bgi = new GreenfootImage ("scrolling_background.png"); int bgiwidth = bgi.getwidth(); public ScrollWorld() { super(1583, 400, 1); update(); } } Public void act () { baseX=(baseX + bgiwidth - 1)%bgiwidth; update(); } Private void update() { If(baseX!=0)getBackground().drawImage(bg... baseX-bgiwidth,0); If(baseX<getwidth())getBackground().draw... } } when it gets to the part that says "Public void act ()" it gives be a class, interface or enum expected error. What is wrong with the code? what do i need to change? thanks! =)
danpost danpost

2014/2/22

#
If you use the 'Auto-layout' feature (press 'Control-Shift-I'), you will notice that your ScrollWorld class is closed out before the 'act' method. In other words, you 'act' method is not placed within the class. Remove one of the closing curly brackets before the 'act' method and it should be ok.
Aspire_Seven Aspire_Seven

2014/2/22

#
Ok, so I deleted a curly bracket so now there is only one above "Public void act ()" and below "Public ScrollWorld". However, now it comes up with the <indentifier> expected error instead of the class, interface, enum error. =P
danpost danpost

2014/2/22

#
'public' and 'private' should both begin with lowercase letters.
Aspire_Seven Aspire_Seven

2014/2/22

#
=/ how didn't I notice that..... Well thats all the errors sorted then. Thanks again! =)
You need to login to post a reply.