0

I have my code set up so I can 1)select what image and 2)the coordinates of the mouse click where the image is going to be placed.

What it currently does it place the right image in the right coordiantes but if I click again somewhere else, it replaces the last image's coords with the new clicked coords.

What I need is that when I click on the canvas, it should place the image permanently and when I click again it places an entirely new image.

Inside the mouse click event

//set new tower coords
if (minY>200){
	int towerID=towers.getTowerId(towerx, towery)
	towerx=minX;
	towery=minY;
	towers.setNewTower(towerType, towerx, towery);
	if (towerType==1)towerImage[towerID]=tower1;
	if (towerType==2)towerImage[towerID]=tower2;
	if (towerType==3)towerImage[towerID]=tower3;
	setnewtower=true;
	repaint();
}

Inside the paint method

if (setnewtower==true){
	int towerID=towers.getTowerId(towerx, towery)
	g.drawImage(towerImage[towerID], towerx, towery, observe);
}

TL;DR
How to create a new .drawImage while running the program?

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Slyvr
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.