Clone entity and run animation again and again

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 ='Plane.009').clone();

             var root ='playing_card');


            console.log(entity,"the cloned entity");

            this.state = false;

            let value = data?.result[0]?.runners[0]?.name;

            // console.log(value);




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

Can I fork your project to debug it? I can’t see where it’s going wrong with small part of script.

Perhaps you can give every clone an unique name by script, to make debugging easier.


this.cardNumber++; = this.cardNumber;

should I add you to the project ?
please share your email

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.

Sure, I have added you ,
Actually I have a list of errors hopefully we can overcome all of those

I debugged your scripts but I could not find the problem.

Probably the player card uses the same texture reference that you also use for the dealer card?

    texture = this.textures.filter((e,i)=> == v)[0].resource;
    texture.addressV =1;
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.
AddCard.prototype.reset= function(value,v,entity){
    texture = this.textures.filter((e,i)=> == v)[0].resource;
    texture.addressV =1;
    entity.render.meshInstances[1].material.diffuseMap = texture;

But what was value for then?

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.

Yes, that’s it @eproasim! I was getting the same result in my sample project first, but after cloning the material, it works as expected. Thanks!

I updated my sample project.

I was passing it to tell the code which entity’s texture I wanted to update.

I shall see this

Thanks a lot this worked

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?

A post was merged into an existing topic: Keep my application running in background

Can you give me a reaction on this first please, to be able to understand your logic?

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

I moved this to another topic because it’s not related here.

Okay , but can you please respond there too?

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
    this.state = true;

How does your statement here make sense?