i have a bgm that keeps giving me "non-static variable bgm cannot be referenced form a static context"
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class MyWorld here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class MyWorld extends World
{
private GreenfootSound bgm;
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
{
super(600, 900, 1);
prepare();
}
/**
* Prepare the world for the start of the program.
* That is: create the initial objects and add them to the world.
*/
private void prepare()
{
Hero hero = new Hero();
addObject(hero,293,373);
hero.setLocation(306,878);
}
public static final String soundFiles =
{
"BsRFTQKY0LPM.128.mp3",
"Hadokowa_-_01_-_Load_HDKW_beta04.mp3",
"Hadokowa_-_04_-___Get_a_Dog_Pet_a_Dog.mp3",
"Lately_Kind_of_Yeah_-_08_-_.mp3",
"sawsquarenoise_-_01_-_Interstellar.mp3"
};
public static void play()
{
if (bgm == null || !bgm.isPlaying())
{
bgm = new GreenfootSound(soundFiles);
bgm.play();
}
}
}
this is my code if any one could help