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

2018/4/24

Bgm is not working, send help post haste,

Casdnova Casdnova

2018/4/24

#
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
danpost danpost

2018/4/24

#
Casdnova wrote...
i have a bgm that keeps giving me "non-static variable bgm cannot be referenced form a static context" << Code Omitted >>
Try changing:
// this
private GreenfootSound bgm;

// to this
private static GreenfootSound bgm;
Casdnova Casdnova

2018/4/25

#
Thank you for that but now it keeps telling me that my music is not a statment
danpost danpost

2018/4/25

#
Casdnova wrote...
Thank you for that but now it keeps telling me that my music is not a statment
Where? which statement? Exactly what did the error message say?
Casdnova Casdnova

2018/4/25

#
At the code "BsRFTQKY0LPM.128.mp3" is keeps say "this is not a statment
danpost danpost

2018/4/25

#
Casdnova wrote...
At the code "BsRFTQKY0LPM.128.mp3" is keeps say "this is not a statment
Post your revised class code -- and please use code tags.
You need to login to post a reply.