FedeCuci

Random Located Sprite Collision

Recommended Posts

Hi everyone,

I am trying to add collision to sprites that are randomly spawned in the map of the game. 

// New object of class Player the sprite name is 'ship'
player = new Player("keyboardMouse", game.world.centerX, game.world.centerY, 200, 200, "12341",
        game.add.sprite(game.world.randomX, game.world.randomY, 'ship'), //Sprite handler object
        Weapons.sniperWeapon.weapon, // Weapon handler object
        ThrustEmitters.ourEmitter.emitter // Thrust emmiter handler object
    );


// loop to randomly place the sprites
for (var i = 0; i < 200; i++){

    var asteroid_brown = game.add.sprite(game.world.randomX, game.world.randomY, 'asteroid');
    var rock = game.add.sprite(game.world.randomX, game.world.randomY, 'rock');

    }



In theory, I would want to make something like the resources in moomoo.io (trees, rocks, gold etc.) You should be able to add collision so that when the player cannot just travel through them and also when shot at you would get 1 of the specific resource.

Also if this can be done in a better way, how would you do it?

Thanks!

 

reee.mov

Share this post


Link to post
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.

Guest
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.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.