im trying to change the background image of my games background mid game to my background inverts but im not able to use the set image command? any Suggestions or alternate codes?


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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | 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 int count; private GreenfootImage B1; private GreenfootImage B2; /** * Constructor for objects of class MyWorld. * */ public MyWorld() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 950 , 600 , 1 ); B1 = new GreenfootImage( "B.jpg" ); B2 = new GreenfootImage( "B2.jpg" ); } public void act() { BackgroundSwitch(); if (Greenfoot.getRandomNumber( 100 ) > 10 ) { addObject( new Border(), 950 , 580 ); /** * lower right */ } if (Greenfoot.getRandomNumber( 100 ) > 10 ) { addObject( new Border2(), 5 , 30 ); /** * uper left */ } if (Greenfoot.getRandomNumber( 100 ) > 10 ) { addObject( new Border3(), 950 , 30 ); /** * lower left */ } if (Greenfoot.getRandomNumber( 100 ) > 10 ) { addObject( new Border4(), 5 , 580 ); /** * uper right */ } } private void BackgroundSwitch() { if (count % 20 == 0 ) { if (getBackground() == B1) setBackground(B2); else setBackground(B1); } count++; } |
1 2 3 4 5 6 7 8 9 10 11 | private void BackgroundSwitch() { if (count % 20 == 0 ) { if (count % 40 == 0 ) setBackground(B1); else setBackground(B2); } count++; } |