Hey, so I am trying to sync object that appears to certain beats in the music. I am pretty sure there is some way to detect the number of frames that have passed during a scenario and equate that to time....30 frames per one second I think
How would I use this info to once that scenario reaches, let's say 150 seconds, to then spawn one of my objects?
Right now I have a paw class that randomly spawns paws but obviously, this is just temporary and I wanted to see if what I wanted to do worked, now I would like some help with the time and frames issue.
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Game here. * * @author (your name) * @version (a version number or a date) */ public class Game extends World { private int leftPawSpawnTimer; private int rightPawSpawnTimer; private int upPawSpawnTimer; private int downPawSpawnTimer; GreenfootSound redBone = new GreenfootSound( "redBone.wav" ); /** * Constructor for objects of class Game. * */ public Game() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super ( 600 , 400 , 1 ); //addObject(new Pause(), 530, 1); //addObject(new LeftPaw(), 45, 500); //those are the correct coordinates for LeftPaw //addObject(new RightPaw(), 293, 700); //addObject(new UpPaw(), 125, 500); //addObject(new DownPaw(), 208, 500); prepare(); } public void prepare() { addObject( new Scoreboard(), 500 , 30 ); } public void act() { leftPawSpawnTimer(); rightPawSpawnTimer(); upPawSpawnTimer(); downPawSpawnTimer(); redBone.play(); } public void leftPawSpawnTimer() { leftPawSpawnTimer = (leftPawSpawnTimer+ 1 )% 100 ; if (leftPawSpawnTimer == 0 ) leftPawSpawn(); } public void rightPawSpawnTimer() { rightPawSpawnTimer = (rightPawSpawnTimer+ 1 )% 350 ; if (rightPawSpawnTimer == 0 ) rightPawSpawn(); } public void upPawSpawnTimer() { upPawSpawnTimer = (upPawSpawnTimer+ 1 )% 275 ; if (upPawSpawnTimer == 0 ) upPawSpawn(); } public void downPawSpawnTimer() { downPawSpawnTimer = (downPawSpawnTimer+ 1 )% 310 ; if (downPawSpawnTimer == 0 ) downPawSpawn(); } public void leftPawSpawn() { addObject( new LeftPaw(), 45 , 500 ); } public void rightPawSpawn() { addObject( new RightPaw(), 293 , 500 ); } public void upPawSpawn() { addObject( new UpPaw(), 125 , 500 ); } public void downPawSpawn() { addObject( new DownPaw(), 208 , 500 ); } } |