• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

ProgrammingGAF, what am I doing wrong? (Drawing from an ArrayList drawing repeatedly)

Status
Not open for further replies.

Mathaou

legacy of cane
fiLkg.png

I isolated the problem into this class. I'm using Slick2D.

Code:
public class Runa extends BasicGame {
	int startTime, tracker;
	public ArrayList<Circle> circ = new ArrayList<Circle>();
	public int[] a = new int[]{
			15, 16, 17, 18, 19, 32, 36, 40, 45, 46, 55, 56, 57, 58, 63, 65, 68, 70, 72, 74, 79, 80, 81, 82, 86, 94, 95, 96, 97, 98, 99, 
			100, 101, 102, 103, 104, 105, 117, 120, 122, 126, 128, 129, 130, 131, 133, 138, 139, 140, 142, 149, 151, 155, 156, 
			158, 164, 166, 172, 174, 180, 182, 184, 188, 189};
	public ArrayList<Integer> aList = new ArrayList<Integer>();
	public Runa(String title) {
		super(title);
	}

	@Override
	public void init(GameContainer c) throws SlickException {
		startTime = 0;
		tracker = 0;
		//this just transfers the hard coded values into an arraylist
		for(int i = 0; i<a.length;i++){
			aList.add(a[i]);
		}
	}
	@Override
	public void update(GameContainer c, int d) throws SlickException {
		//this calculates the rhythm of the game
		startTime+=d;
		if(startTime>((60/(calcBPM(195.8,89)))*1000)){
			startTime=0;
			tracker++;
		}
		
		//this adds a new circle every time the current beat (tracker) reaches a beat on the aList
		if(aList.indexOf(tracker)>0)
			circ.add(new Circle(50,50,50));
		//this should just move one circle at a time, meaning I thought that only one circle would be added above, and move it down 4 px
		for(Circle circle: circ)
			circle.setCenterY(circle.getCenterY()+4);
	}
	
	@Override
	public void render(GameContainer c, Graphics g) throws SlickException {
		//draws each circle in the arraylist
		g.setColor(Color.red);
		for(Circle circle: circ)
			g.draw(circle);
	}
	//calculates the bpm
	public double calcBPM(double d, int numSecs){
		return d*60/numSecs;
	}
	public static void main(String[]args) throws SlickException{
		new AppGameContainer(new Runa("Test"),680, 480, false).start();
	}
}
Why is it doing that weird stretch thing? Is that because I'm using an arraylist?
 

balgajo

Member
How would I do that?
I'm not familiar with Slick2d(C++ guy) though search for framebuffer clearing or something like that. Also I'd recommend searching for double buffering implementation to avoid flickering. Maybe framework will even do it for you.
 

Mathaou

legacy of cane
I'm not familiar with Slick2d(C++ guy) though search for framebuffer clearing or something like that. Also I'd recommend searching for double buffering implementation to avoid flickering. Maybe framework will even do it for you.

The problem only arises with arraylists tho. I've created a single circle and I can move it just fine. No issues there.

I haven't included double buffering, but it seems to be fine. I think slick does it for me.
 

Alexlf

Member
It looks like you're adding a new circle every update in addition to incrementing the ones you already have. Could that be it?

Edit: That didn't come out how I meant it. I mean you never remove your circles in circ, but keep adding them.
 

Mathaou

legacy of cane
It looks like you're adding a new circle every update in addition to incrementing the ones you already have. Could that be it?

I'm only adding a new circle when the current beat of the song is equal to a beat already in a set list. Then I just want every circle to move down.

In my other code I use this to get rid of circles when I don't need them anymore.
Code:
f = (kFList.get(kFList.indexOf(f)).getY()>HEIGHT)?null:f;
 

Alexlf

Member
I'm only adding a new circle when the current beat of the song is equal to a beat already in a set list. Then I just want every circle to move down.

In my other code I use this to get rid of circles when I don't need them anymore.
Code:
f = (kFList.get(kFList.indexOf(f)).getY()>HEIGHT)?null:f;

Ah, alright. So they get removed elsewhere. Where's the code where you draw the letters and the thing behind them?
 

Mathaou

legacy of cane
Ah, alright. So they get removed elsewhere. Where's the code where you draw the letters and the thing behind them?

Those aren't really part of the problem are they?

But in case I'm a dumbass and they are, here ya go. Not everything has been changed, as I've been debugging with just the A. FallingObject just has a position and image in it.

Code:
	public JojoGame(String title) throws SlickException {
		super(title);
	}
	//redo hit times using this. This returns the time in milliseconds, so initialize a value to act as the 0 (start time), then hit times from the 0. 
	public int getTime() {
	    return (int) ((Sys.getTime() * 1000) / Sys.getTimerResolution());
	}
	@Override
	public void init(GameContainer c) throws SlickException {
		startTime = 0;
		tracker = 0;
		try {
			read = new TXTRead(fileKey);
			transferValues(read.getArr());
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		
		//background
		background = loadImage("jojo");
		
		//hit rectangle, image goes over
		bar = loadImage("jojoBar");
		barCol = new Rectangle(0, 430, c.getWidth(), 20);
		fistA = loadImage("fistA");
		fistS = loadImage("fistS");
		fistK = loadImage("fistK");
		fistL = loadImage("fistL");
		
		//score ints
		score = 0;
		multiplier = 1;
		
		//location variable
		
		//music is loaded here
		
		try {
			wavEffect = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("res/op2.wav"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		wavEffect.playAsMusic(1.0f, 1.0f, false);
		
		//end music load
	}
	//196 beats in OP2, over 89 seconds. 
	public double calcBPM(double d, int numSecs){
		return d*60/numSecs;
	}
	@Override
	public void update(GameContainer c, int d) throws SlickException {
		startTime+=d;
		if(startTime>((60/(calcBPM(195.8,89)))*1000)){
			startTime=0;
			tracker++;
		}
		//make every image
		
		if(aList.indexOf(tracker+5)>0)
			aFList.add(new FallingObject(fistA,WIDTH/10*2-radius-5,0-radius,radius));
		if(sList.contains(tracker+5))
			sFList.add(new FallingObject(loadImage("fistS"),WIDTH/10*4-radius-5,0-radius,radius));
		if(kList.contains(tracker+5))
			kFList.add(new FallingObject(loadImage("fistK"),WIDTH/10*6-radius,0-radius,radius));
		if(lList.contains(tracker+5))
			lFList.add(new FallingObject(loadImage("fistL"),WIDTH/10*8-radius-5,0-radius,radius));
		//move every image
		for(FallingObject f: aFList){
			f.setY(f.getY()+4);
			f = (f.getY()>HEIGHT)?null:f;
		}
		for(FallingObject f: sFList){
			f.setY(f.getY()+4);
			f = (sFList.get(sFList.indexOf(f)).getY()>HEIGHT)?null:f;
		}
		for(FallingObject f: kFList){
			f.setY(f.getY()+4);
			f = (kFList.get(kFList.indexOf(f)).getY()>HEIGHT)?null:f;
		}
		for(FallingObject f: lFList){
			f.setY(f.getY()+4);
			f = (lFList.get(lFList.indexOf(f)).getY()>HEIGHT)?null:f;
		}
	}
	@Override
	public void render(GameContainer c, Graphics g) throws SlickException {
		c.setAlwaysRender(true);
		c.setUpdateOnlyWhenVisible(true);
		c.setTargetFrameRate(60);
		background.draw(0, 0);
		g.setColor(Color.transparent);
		g.draw(barCol);
		bar.draw(0,0);
		g.setColor(Color.black);
		for(Circle circle: circ)
			g.draw(circle);
		
		//render every image
		for(FallingObject f: aFList){
			g.drawImage(f.getImg(), f.getX(), f.getY());
		}
		for(FallingObject f: sFList){
			f.getImg().draw(f.getX(), f.getY());
		}
		for(FallingObject f: kFList){
			f.getImg().draw(f.getX(), f.getY());
		}
		for(FallingObject f: lFList){
			f.getImg().draw(f.getX(), f.getY());
		}
		g.drawString(Integer.toString(score),640,20);
		g.drawString("X"+Integer.toString(multiplier), 620, 400);
	}
	public static void main(String[]args) throws SlickException{
		new AppGameContainer(new JojoGame("JojoMania"),WIDTH, HEIGHT, false).start();
	}
	private Image loadImage(String key) throws SlickException{
		return new Image("res/"+key+".png");
	}
	public int readLines(String file) throws IOException{
		fileToRead = new FileReader(file);
		bf = new BufferedReader(fileToRead);
		
		String aLine;
		int numLines = 0;
		while((aLine = bf.readLine())!=null){
			numLines++;
		}
		bf.close();
		return numLines;
	}
	public void transferValues(String[] arr) throws IOException{
 

Makai

Member
Code:
for(FallingObject f: aFList){
	f.setY(f.getY()+4);
	f = (f.getY()>HEIGHT)?null:f;
}
for(FallingObject f: sFList){
	f.setY(f.getY()+4);
	f = (sFList.get(sFList.indexOf(f)).getY()>HEIGHT)?null:f;
}
for(FallingObject f: kFList){
	f.setY(f.getY()+4);
	f = (kFList.get(kFList.indexOf(f)).getY()>HEIGHT)?null:f;
}
for(FallingObject f: lFList){
	f.setY(f.getY()+4);
	f = (lFList.get(lFList.indexOf(f)).getY()>HEIGHT)?null:f;
}

Okay, anytime you have this situation, you need to make a new method.
 

Salamando

Member
Which IDE are you developing this in? This is Java based, so I'm hoping Eclipse. Debugging it from there would be pretty easy. If you can see the console, before you render a specific list (alist, for example), just do a System.out.println(aFList.size()). If it spits out numbers greater than like 2, you know your issue is with too much stuff getting put in it.
 

Mathaou

legacy of cane
Code:
for(FallingObject f: aFList){
	f.setY(f.getY()+4);
	f = (f.getY()>HEIGHT)?null:f;
}
for(FallingObject f: sFList){
	f.setY(f.getY()+4);
	f = (sFList.get(sFList.indexOf(f)).getY()>HEIGHT)?null:f;
}
for(FallingObject f: kFList){
	f.setY(f.getY()+4);
	f = (kFList.get(kFList.indexOf(f)).getY()>HEIGHT)?null:f;
}
for(FallingObject f: lFList){
	f.setY(f.getY()+4);
	f = (lFList.get(lFList.indexOf(f)).getY()>HEIGHT)?null:f;
}

Okay, anytime you have this situation, you need to make a new method.

Ah, yes. That was from earlier where I was paranoid that everything was going to fall apart if I tried making any changes. I'll change it back later.
 
Maybe not your bug but I don't think this line does what you think it does:

Code:
f = (f.getY()>HEIGHT)?null:f;

If Java is anything like C# (and it seems to be), f is a copy of the reference to the instance in the collection, so your code is the equivalent of (forgive syntax, I don't program in Java but you should get the idea):

Code:
for (int i = 0; i < aFList.count(); ++i)
{
    // Copy reference to f
    FallingObject f = aFList[i];
    f.setY(f.getY() + 4);

    // Set local f to null, does not modify collection
    f = (f.getY()>HEIGHT)?null:f;
}
 

Mathaou

legacy of cane
Maybe not your bug but I don't think this line does what you think it does:

Code:
f = (f.getY()>HEIGHT)?null:f;

If Java is anything like C# (and it seems to be), f is a copy of the reference to the instance in the collection, so your code is the equivalent of (forgive syntax, I don't program in Java but you should get the idea):

Code:
for (int i = 0; i < aFList.count(); ++i)
{
    // Copy reference to f
    FallingObject f = aFList[i];
    f.setY(f.getY() + 4);

    // Set local f to null, does not modify collection
    f = (f.getY()>HEIGHT)?null:f;
}
Thanks, I fixed that. I also noticed that what stops the long stream of images is the next image being called. What does that tell anyone?
 
Dear god..


I can understand this!

I mean, I only started learning programming a couple of months ago, so I can't actually really help, but I can understand what you're trying to do here, and that fact is nuts to me, now :)

Good luck with the array, dude!
 

Mathaou

legacy of cane
Dear god..


I can understand this!

I mean, I only started learning programming a couple of months ago, so I can't actually really help, but I can understand what you're trying to do here, and that fact is nuts to me, now :)

Good luck with the array, dude!

Is it similar to how I felt?

I have been having a hard time so far. Probs because I'm trying to force things I don't understand to do things I'm not sure they can.
 

Alexlf

Member
Thanks, I fixed that. I also noticed that what stops the long stream of images is the next image being called. What does that tell anyone?

Can you clarify what you mean "the next image being called"? If you mean you're re-rendering the background then your issue is exactly what balgajo was getting at. Every time you want to update the screen you need to redraw every part, back to front. So the background first, then your jojobar, then your letters and circles, etc.

EDIT: Nevermind, I see you are doing that right in the render function of the code you just posted.
 

ElTorro

I wanted to dominate the living room. Then I took an ESRAM in the knee.
How would I do that?

Thanks, I fixed that. I also noticed that what stops the long stream of images is the next image being called. What does that tell anyone?

As others have said, when you are drawing with virtually any graphics APIs, you are drawing to a buffer&#8212;usually a pixel buffer. This buffer then needs to be sent explicitly to the display, while the next frame then is drawn into a new pixel buffer. The framework that you are using seems to manage this for you. But you need to tell it when you are finished drawing the current frame.

If I see it correctly from looking at the JavaDoc of the framework, you need to call the flush method on the Graphics object. I'd expect the framework to do that for you, since it is defining and calling the render method, but you never know. The documentation is pretty shitty, as they usually are.

Code:
public void render(GameContainer c, Graphics g) throws SlickException {
    //draws each circle in the arraylist
    g.setColor(Color.red);
    for(Circle circle : circ) {
        g.draw(circle);
    }
    g.flush();
}

By the way, the code is generally not idiomatic Java and has several issues. If you are interested in improving your Java, I recommend this book, which is essential reading for Java programmers.

51%2BQT0CAoEL._SX384_BO1,204,203,200_.jpg
 

Mathaou

legacy of cane
Can you clarify what you mean "the next image being called"? If you mean you're re-rendering the background then your issue is exactly what balgajo was getting at. Every time you want to update the screen you need to redraw every part, back to front. So the background first, then your jojobar, then your letters and circles, etc.

The most annoying part is that's what I'm doing.
Code:
	public void render(GameContainer c, Graphics g) throws SlickException {
		c.setAlwaysRender(true);
		c.setUpdateOnlyWhenVisible(true);
		c.setTargetFrameRate(60);
		background.draw(0, 0);
		g.setColor(Color.transparent);
		g.draw(barCol);
		bar.draw(0,0);
		g.setColor(Color.black);
		
		//render every image
		drawFist(g,aFList);
		drawFist(g,sFList);
		drawFist(g,kFList);
		drawFist(g,lFList);
		
		g.drawString(Integer.toString(score),640,20);
		g.drawString("X"+Integer.toString(multiplier), 620, 400);
	}

Do you have a repository? I could probably take a better look if I can see all your classes.

edit: also, yes, just like that. :)

I'm a senior in highschool, so I haven't had much use for github so far.

I just have the one class and then one more that just has images and positioning in it.

Code:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;import java.util.Arrays;
import java.util.Collections;

import org.lwjgl.Sys;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Circle;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.openal.Audio;
import org.newdawn.slick.openal.AudioLoader;
import org.newdawn.slick.util.ResourceLoader;

public class JojoGame extends BasicGame{

	public Circle circleA, circleS, circleK, circleL;
	public Image background, bar, fistA, fistS, fistK, fistL;
	public Rectangle barCol;
	public Audio wavEffect;

	public float radius = 20;
	public int multiplier,score, aLoc = 0, sLoc = 0, kLoc = 0, lLoc = 0;
	public final static int WIDTH = 680;
	public static final int HEIGHT = 480;
	long magicNumber;
	/*///////////////////////////////////////////////////////////////////////
	 * 														Timers
	 *///////////////////////////////////////////////////////////////////////

	public ArrayList<FallingObject>aFList = new ArrayList<FallingObject>();
	public ArrayList<FallingObject>sFList = new ArrayList<FallingObject>();
	public ArrayList<FallingObject>kFList = new ArrayList<FallingObject>();
	public ArrayList<FallingObject>lFList = new ArrayList<FallingObject>();
	
	public ArrayList<Circle> circ = new ArrayList<Circle>();
	
	public ArrayList<Integer> aList = new ArrayList<Integer>();
	public ArrayList<Integer> sList = new ArrayList<Integer>();
	public ArrayList<Integer> kList = new ArrayList<Integer>();
	public ArrayList<Integer> lList = new ArrayList<Integer>();
	
	FileReader fileToRead;
	BufferedReader bf;
	
	String fileKey = "res/beatSheet.txt";
	TXTRead read;
	
	public int startTime, tracker;
	public JojoGame(String title) throws SlickException {
		super(title);
	}
	//redo hit times using this. This returns the time in milliseconds, so initialize a value to act as the 0 (start time), then hit times from the 0. 
	public int getTime() {
	    return (int) ((Sys.getTime() * 1000) / Sys.getTimerResolution());
	}
	@Override
	public void init(GameContainer c) throws SlickException {
		startTime = 0;
		tracker = 0;
		try {
			read = new TXTRead(fileKey);
			transferValues(read.getArr());
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		
		//background
		background = loadImage("jojo");
		
		//hit rectangle, image goes over
		bar = loadImage("jojoBar");
		barCol = new Rectangle(0, 430, c.getWidth(), 20);
		fistA = loadImage("fistA");
		fistS = loadImage("fistS");
		fistK = loadImage("fistK");
		fistL = loadImage("fistL");
		
		//score ints
		score = 0;
		multiplier = 1;
		
		//location variable
		
		//music is loaded here
		
		try {
			wavEffect = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("res/op2.wav"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		wavEffect.playAsMusic(1.0f, 1.0f, false);
		
		//end music load
	}
	//196 beats in OP2, over 89 seconds. 
	public double calcBPM(double d, int numSecs){
		return d*60/numSecs;
	}
	@Override
	public void update(GameContainer c, int d) throws SlickException {
		startTime+=d;
		if(startTime>((60/(calcBPM(195.8,89)))*1000)){
			startTime=0;
			tracker++;
		}
		//make every image
		addToList(aList, aFList, fistA, 2, 5);
		//move every image
		moveImage(aFList);
		moveImage(sFList);
		moveImage(kFList);
		moveImage(lFList);
	}
	public void addToList(ArrayList<Integer> list, ArrayList<FallingObject> fList, Image img, int mult, int tweak){
		if(list.contains(tracker))
			fList.add(new FallingObject(img,WIDTH/10*mult-radius-tweak,0-radius,radius));
	}
	@Override
	public void render(GameContainer c, Graphics g) throws SlickException {
		//c.setAlwaysRender(true);
		//c.setUpdateOnlyWhenVisible(true);
		c.setTargetFrameRate(60);
		background.draw(0, 0);
		g.setColor(Color.transparent);
		g.draw(barCol);
		bar.draw(0,0);
		g.setColor(Color.black);
		
		//render every image
		drawFist(g,aFList);
		drawFist(g,sFList);
		drawFist(g,kFList);
		drawFist(g,lFList);
		
		g.drawString(Integer.toString(score),640,20);
		g.drawString("X"+Integer.toString(multiplier), 620, 400);
	}
	public static void main(String[]args) throws SlickException{
		new AppGameContainer(new JojoGame("JojoMania"),WIDTH, HEIGHT, false).start();
	}
	
	public void moveImage(ArrayList<FallingObject> list) throws SlickException{
		for(int i = 0; i < list.size(); i++){
			list.get(i).setY(list.get(i).getY()+4);
		}
	}
	public void drawFist(Graphics g, ArrayList<FallingObject> fList){
		for(int i = 0; i < fList.size(); i++){
			g.drawImage(fList.get(i).getImg(), fList.get(i).getX(), fList.get(i).getY());
		}
	}
	private Image loadImage(String key) throws SlickException{
		return new Image("res/"+key+".png");
	}
	public int readLines(String file) throws IOException{
		fileToRead = new FileReader(file);
		bf = new BufferedReader(fileToRead);
		
		String aLine;
		int numLines = 0;
		while((aLine = bf.readLine())!=null){
			numLines++;
		}
		bf.close();
		return numLines;
	}
	public void transferValues(String[] arr) throws IOException{
		for(int i = 0; i < readLines(fileKey);i++){
			if(arr[i].contains("A"))
				aList.add(Integer.parseInt(arr[i].substring(3)));
			if(arr[i].contains("S"))
				sList.add(Integer.parseInt(arr[i].substring(3)));
			if(arr[i].contains("K"))
				kList.add(Integer.parseInt(arr[i].substring(3)));
			if(arr[i].contains("L"))
				lList.add(Integer.parseInt(arr[i].substring(3)));
		}
		Collections.sort(aList);
		Collections.sort(sList);
		Collections.sort(kList);
		Collections.sort(lList);
		System.out.println(aList.toString()	);
	}
	
	////////////////////////////////////////////////////////////////////////////////
	//getters and setters
	///////////////////////////////////////////////////////////////////////////////

As others have said, when you are drawing with virtually any graphics APIs, you are drawing to a buffer&#8212;usually a pixel buffer. This buffer then needs to be sent explicitly to the display, while the next frame then is drawn into a new pixel buffer. The framework that you are using seems to manage this for you. But you need to tell it when you are finished drawing the current frame.

If I see it correctly from looking at the JavaDoc of the framework, you need to call the flush method on the Graphics object.

Code:
public void render(GameContainer c, Graphics g) throws SlickException {
    //draws each circle in the arraylist
    g.setColor(Color.red);
	  for(Circle circle: circ) {
        g.draw(circle);
    }
    g.flush();
}

By the way, the code is generally not idiomatic Java and has several issues. If you are interested in improving your Java, I recommend this book, which is essential reading for Java programmers.

51%2BQT0CAoEL._SX384_BO1,204,203,200_.jpg
Also, I used flush and it didn't work.

I'm in highschool, but I'll for sure check that out.
 

ElTorro

I wanted to dominate the living room. Then I took an ESRAM in the knee.
The most annoying part is that's what I'm doing.
Code:
Also, I used flush and it didn't work.[/QUOTE]

If I see it correctly, you are adding new drawable objects in every frame:

[CODE]addToList(aList, aFList, fistA, 2, 5);

This would naturally explain why you are drawing new objects every frame.

Your goal is to create a collection of drawable objects, update their position in every frame, and then draw them in their updated positions, correct?
 

Mathaou

legacy of cane
If I see it correctly, you are adding new circles in every frame:

Code:
addToList(aList, aFList, fistA, 2, 5);

This would naturally explain why you are drawing new circles every frame.

Your goal is to create a collection of drawable objects, update their position in every frame, and then draw them in their updated positions, correct?

Yes. But I thought my if statement (if(list.contains(tracker))) would allow only one object to be added to the list. I'm perplexed as to why that isn't so.
 

ElTorro

I wanted to dominate the living room. Then I took an ESRAM in the knee.
Yes. But I thought my if statement (if(list.contains(tracker))) would allow only one object to be added to the list. I'm perplexed as to why that isn't so.

I have no idea what you are intending to do with those lists. Maybe you should describe your requirements for that code in prosa first.
 

Salamando

Member
Yes. But I thought my if statement (if(list.contains(tracker))) would allow only one object to be added to the list. I'm perplexed as to why that isn't so.

Try modifying
Code:
	public void addToList(ArrayList<Integer> list, ArrayList<FallingObject> fList, Image img, int mult, int tweak){
		if(list.contains(tracker))
			fList.add(new FallingObject(img,WIDTH/10*mult-radius-tweak,0-radius,radius));
	}
to
Code:
	public void addToList(ArrayList<Integer> list, ArrayList<FallingObject> fList, Image img, int mult, int tweak){
		if(list.contains(tracker)){
                        list.remove(tracker);
			fList.add(new FallingObject(img,WIDTH/10*mult-radius-tweak,0-radius,radius));
                }
	}

Here's what's happening...

Assume you enter public void update(GameContainer c, int d) with a small d (that's what she said)...something small enough to not trip the value and increase the Tracker variable. Tracker remains unchanged.

In your first post, aList looks to contain the beats you want to fire notes on. Whenever you enter addToList, the tracker is still the same, and the beat list hasn't changed either. It causes you to create a new circle a few fractions of a second later.

Contains just checks if that element is currently in the arraylist. It doesn't remove it.
 
Someone mentioned it before, but I don't see where you're removing your Circle objects from your circ List, which is where you are drawing from.

The kFList code you posted wouldn't kill the object if it's also stored in the circ list.

Try printing out the contents or at least size of your circ List on each iteration (or better yet, use a debugger) to verify.
 

Salamando

Member
Wonderful! Now, if you're willing to accept some advice from a Java pro...

Learn Eclipse. It has breakpoints you can use to step through code, check variable values at any point in execution, and so much more. Saves days in debugging.

Also GIT. Even if you're not sharing code with people, version control is a lifesaver.
 
Here's what's happening...

Assume you enter public void update(GameContainer c, int d) with a small d (that's what she said)...something small enough to not trip the value and increase the Tracker variable. Tracker remains unchanged.

In your first post, aList looks to contain the beats you want to fire notes on. Whenever you enter addToList, the tracker is still the same, and the beat list hasn't changed either. It causes you to create a new circle a few fractions of a second later.

Well spotted.
 

Mathaou

legacy of cane
Wonderful! Now, if you're willing to accept some advice from a Java pro...

Learn Eclipse. It has breakpoints you can use to step through code, check variable values at any point in execution, and so much more. Saves days in debugging.

Also GIT. Even if you're not sharing code with people, version control is a lifesaver.

Yeah my teacher hasn't taught us how to debug or any of that - and we're supposed to learn how to use git by the end of the year to better prepare us for college.

Those are two things that are definitely high on my priority list.
 
Status
Not open for further replies.
Top Bottom