Jump to content

How to group createMultiple sprites ?


vmars316
 Share

Recommended Posts

Hello & Thanks ,

I have 2 images (actually 4 in final code) named thruth01sprite and thruth02sprite . 

Rather than duplicate this code , I would like to group them:

Quote

        if (truth02sprite.x > worldBoundsWidth) 
    {
        truth02sprite.scale.setTo(-1, 1); 
        truth02sprite.body.velocity.x = -100;
//        truth02sprite.body.x = 50;
        score ++;
        scoreText.text = 'Score : ' + score;
    }
        if (truth02sprite.x < 0) 
    {
        truth02sprite.scale.setTo(1, 1); 
        truth02sprite.body.velocity.x = +100;
//        truth02sprite.body.x = 50;
        score ++;
        scoreText.text = 'Score : ' + score;
    }

But I'm not having much luck in writing the group code:

    //  All 40 of them
    bullets.createMultiple(10, 'bullet');   // bullet becomes bullets 
    bullets.setAll('anchor.x', 0.5);
    bullets.setAll('anchor.y', 0.5);
//    bullets.body.velocity.y = -300;
//    bullets.body.acceleration.y = -300;
    //  All 4 of them
    okGuys.createMultiple(2, ('truth01sprite','truth02sprite'));   // truth01sprite becomes okGuys 
    okGuys.setAll('anchor.x', 0.5);
    okGuys.setAll('anchor.y', 0.5);    

The bullets code works fine , but the okGuys no go .

Pls, how can I do this properly ?

Thanks

Link to comment
Share on other sites

2 hours ago, vmars316 said:

okGuys.createMultiple(2, ('truth01sprite','truth02sprite'));

That part that goes "('truth01sprite', 'truth02sprite')" is not really a thing in JavaScript. Or, at least, it's not doing what you want.

You probably want to just call "okGuys.create" twice with the different sprite keys and then start calling all the setAll things.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...