Listen… I’ve just read through this thread and it seems you guys are having a bit of a hard time communicating, so I’ll give it a go.
You have a Skyscraper
Skyscraper s
declared as a variable inside your main class. This is also the one that you are rendering, by getting an image stored inside that ONE instance of Skyscraper.
When you are testing whether
VK_SPACE
has been pressed is where your little problem occurs. You want to place a new skyscraper, I’m guessing? The problem is you aren’t creating another instance of Skyscraper and are instead moving the existing one.
s.placeSkyscraper()
is only ever going to move
s
. This means that you’re going to need a new way to store, create and render your skyscrapers.
Let’s start with storing.
Many, many people have recommended an
ArrayList
in this thread, and I will as well because they are incredibly easy to use. So, we need to declare one in the same place you’ve declared
s
. Next, you need to update your render loop to accommodate for the fact that you now need to iterate through a list to get your skyscrapers:
for (Skyscraper sky : muhskyscrapers){
//use sky here as you would have used s before…
}
So we have ourselves a brand new ArrayList. The problem is we haven’t added anything to it. This can be fixed in your
keyPressed
function. Instead of s.placeSkyscraper, do this:
Skyscraper s = new Skyscraper();
s.placeSkyscraper(x, y);
muhskyscrapers.add(s);
I’d also recommend adding two parameters to the Skyscraper constructor to take an x and y value, just for convenience.