Answer the question
In order to leave comments, you need to log in
How to handle a touch on the screen in the area where the sprite is located?
Hey!
All those involved with the past holidays!
There is a class, when instantiated, a collection appears that contains sprites.
Everything is as usual:
I declare a variable in the class static ArrayList<Sprite> caterpillar;
I fill in the constructor with sprites with this function:
private void building(){
//тут будет забивать массив спрайтами
for( int i = 0; i < numberOfElements; i ++){
sprite = new Sprite(region);
sprite.setX(positionX);
sprite.setY(positionY);
caterpillar.add(sprite);
positionY -= 150;
}
}
public static ArrayList<Sprite> getCaterpillar(){return caterpillar;}
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
for(Sprite i : ourCaterpillar){ if(i.getBoundingRectangle().contains(screenX, screenY)) System.out.println("Есть попадание!!"); }
for(int i = 0 ; i < 8; i ++){
if(ourCaterpillar.get(i).getBoundingRectangle().contains(screenX,screenY)){ System.out.println("Есть попадание"); }
}
System.out.println(ourCaterpillar.size());
return true;
}
Answer the question
In order to leave comments, you need to log in
The problem turned out to be that despite rendering the sprite larger than it is, the
container is looking for points that fill the original size of the sprite.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question