…okay i actually made a test-script that worked. the above was not quite right, but the general idea.
This actually works:
const gameState = {}
function preload(){
this.load.image("Card","https://upload.wikimedia.org/wikipedia/en/thumb/a/aa/Magic_the_gathering-card_back.jpg/220px-Magic_the_gathering-card_back.jpg");
}
function create(){
//creating cards 1-5
gameState.card1 = this.add.sprite(724,977,"Card");
gameState.card2 = this.add.sprite(852,977,"Card");
gameState.card3 = this.add.sprite(980,977,"Card");
gameState.card4 = this.add.sprite(1108,977,"Card");
gameState.card5 = this.add.sprite(1236,977,"Card");
//setting default sizes.
gameState.card1.setSize (128,150);
gameState.card2.setSize (128,150);
gameState.card3.setSize (128,150);
gameState.card4.setSize (128,150);
gameState.card5.setSize (128,150);
//making cards interactive.
gameState.card1.setInteractive();
gameState.card2.setInteractive();
gameState.card3.setInteractive();
gameState.card4.setInteractive();
gameState.card5.setInteractive();
//creating max card size for later use.
gameState.maxcardsize = 1.3;
//Checking card for mouse click
//creating debug texts
gameState.where_mouse_x = this.add.text(100,0, "asd",{fontSize:80});
gameState.where_mouse_y = this.add.text(100,100,"dsa",{fontSize:80});
// gameState.text1 = this.add.text(100,400,"asd",{fontSize:80});
// gameState.text2 = this.add.text(100,500,"asd",{fontSize:80});
// gameState.text3 = this.add.text(100,600,"asd",{fontSize:80});
// gameState.text4 = this.add.text(100,700,"asd",{fontSize:80});
// gameState.text5 = this.add.text(100,800,"asd",{fontSize:80});
}
function update(){
//checking where the mouse is.
mousex = Math.floor(game.input.mousePointer.x);
mousey = Math.floor(game.input.mousePointer.y);
//writing to debug text where mouse is.
gameState.where_mouse_x.setText("x: " + mousex);
gameState.where_mouse_y.setText("y: " + mousey);
//Resetting depth to ensure Depth is correct and only affected on cards being resized.
gameState.card1.setDepth(0);
gameState.card2.setDepth(0);
gameState.card3.setDepth(0);
gameState.card4.setDepth(0);
gameState.card5.setDepth(0);
//if in bounds of card box, checks every cards distance from the mouse and rescales if within threshold (both upper and lower)
if ( 550 < mousex && mousex < 1350){
scale1 = (100/Math.abs(mousex - 724));
if (scale1 > 1 && scale1 < gameState.maxcardsize){
gameState.card1.setScale(scale1,scale1);
}
scale2 = (100/Math.abs(mousex - 852));
if (scale2 > 1 && scale2 < gameState.maxcardsize){
gameState.card2.setScale(scale2,scale2);
}
scale3 = (100/Math.abs(mousex - 980));
if (scale3 > 1 && scale3 < gameState.maxcardsize){
gameState.card3.setScale(scale3,scale3);
}
scale4 = (100/Math.abs(mousex - 1108));
if (scale4 > 1 && scale4 < gameState.maxcardsize){
gameState.card4.setScale(scale4,scale4);
}
scale5 = (100/Math.abs(mousex - 1236));
if (scale5 > 1 && scale5 < gameState.maxcardsize){
gameState.card5.setScale(scale5,scale5);
}
gameState.card1.setDepth(scale1);
gameState.card2.setDepth(scale2);
gameState.card3.setDepth(scale3);
gameState.card4.setDepth(scale4);
gameState.card5.setDepth(scale5);
}
if ( 550 > mousex || mousex > 1350){ //
gameState.card1.setScale(1,1);
gameState.card2.setScale(1,1);
gameState.card3.setScale(1,1);
gameState.card4.setScale(1,1);
gameState.card5.setScale(1,1);
}
}
const config = {
width: 1920,
height:1080,
backgroundColor:0x00008b,
scene:{
preload,
create,
update,
}
};
const game = new Phaser.Game(config);
i just used Magic cards as an example. also note that the cards dont have the slight tilt you have.