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.
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);
}
}


