I am creating my entity in my game.js script(which is my manager script)
from here I call this script above and pass the entity and value of texture I wish to add to that particular entity
Below is the code for adding my clone entity to scene
entity = this.app.root.findByName('Plane.009').clone();
var root = this.app.root.findByName('playing_card');
root.addChild(entity);
console.log(entity,"the cloned entity");
this.state = false;
let value = data?.result[0]?.runners[0]?.name;
// console.log(value);
this.app.fire("game:start-card",value,entity);
this.app.fire("game:start-camera",value,entity);
this.app.fire("game:setCard",value,`${data?.result[0]?.runners[0].card[0]?.toLowerCase()}.png`,entity);
Also is there any way I can keep on running my application in background , because when I switch tabs my animation stops and continues from the point where I had stopped , instead I just want it to continue in background
If you donât want to share a link of your project on the forum you can add albertos to the project. Then I will fork the project to find out where it is going wrong, without affecting the original project.
Your *addCard function* is a bit odd. I doensn't matter if `value` is `player` or `dealer` because for both you do exactly the same. That means that you can clear a lot of code.
Iâm wondering if the material itself should be cloned and then edited. Presumably, if youâre editing the material itself and both entities use the same material, it makes sense that both would update to the same texture, since the material is an asset. Try cloning the material before applying the new texture to the clone.
I also had another query , when you play my code, you will see when the card exits , due to some reason exit animation is only applied to the player card and dealer card just disappears.
Can you please help me debug this?
So my current mesh has 2 materials I only wish to update one side thats why I set address as one , as my materials are in my _meshInstances and inside there is an array of materials which I update, with the help of code in your test project you shared I was able to implement what i needed in my project, I cloned my materials and updated the material which i wanted to apply texture to , since you are a part of the project you can check it
thanks for the help
Also now as we know playcanvas stops all animations in background. My whole script works on the base of my api and the response that comes from that API, but now i face a major problem.
Letâs say now, I get a response==true from my api, but at this point user has minimized/switched tabs/just loading the game. At these time I already have a true from my api and animation triggers when the screen loads again or when person comes back to the tab.
Now what I want is that, if the person comes in at a particular time then it should load in the place where it is supposed to , for example if I have got a response from the api prior to user coming only then I wish to show the card already placed in its respective box and not show the animation.
For this I thought I can use states like in react, so I wanted to know if there is any method to do this in playcanvas where I can manage the game as if it is running in background and load it in the same status when the user comes in
Itâs a little difficult to debug your project because Iâm unable to see where you get the information from, for statements like below.
if (data?.result[0]?.runners[0].card[0]) {
// your code
}
It can takes a long time before a new card is given, probably a part of the game I donât inderstand, but I saw the long waiting time is controlled with the statements this.state, this.state2 and this.state3. But how you use that states looks again a little odd to me. For example the statement below.
if (this.state === true) {
// your code
}
else{
this.state = true;
}