Is there a way to get a sprite’s texture/name of the spritesheet it is using?
I’m asking because I’m trying to make a function where an item falls and its position gets reset to the top of the screen once it goes out of the world bounds. The problem is that I have 3 different types of items and I want to make a general function to reset an item regardless of what kind of item it is.
Is this possible? Is this a good way to go about this? I have considered making a separate function for each type of object, but it seems like a waste, since the functions would be very similar…
Here’s my code:
//falling items
itemFall(item, accel) {
//set acceleration
item.body.setAcceleration(0,accel);
//reset item when it falls beyond the world boundary (top/bottom)
if (item.y > config.height) {
this.itemReset(item);
} else if (item.y < 0){
this.itemReset(item);
}
//reset item when it falls beyond the world boundary (left/right)
if (item.x > config.width) {
this.itemReset(item);
} else if (item.x < 0){
this.itemReset(item);
}
}
itemReset(item) {
item.y = 0;
var randomX = Phaser.Math.Between(0, config.width);
item.x = randomX;
//this is where I want to detect the texture and act accordingly
//this particular instance only deals with one type of item - tetrominos
item.setTexture("tetromino", Phaser.Math.Between(0, 59));
}
I’d appreciate any advice in this situation