Jump to content

How to generate random sprite in phaser


Recommended Posts

I have a function 'randomTiles();' which is meant to generate random falling tiles (like rain drops) from the top of the page downwards, what happens is the tile are generated randomly from different areas of the game window, also this isn't working 'sprite1.body.setSize(50, 26, 0, 0);' I don't why.

here is what I have done

function releaseTiles() {

//sprite1 = game.add.sprite(300, 50, 'tile');
sprite1 = game.add.sprite((Math.random() * 20000), game.world.randomY, 'tile');
sprite1.name = 'tile';
game.physics.enable(sprite1, Phaser.Physics.ARCADE);
sprite1.body.velocity.y = 100;
sprite1.body.setSize(50, 26, 0, 0);


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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