smooth_penguin Posted January 9, 2014 Share Posted January 9, 2014 Hey! I'm using phaserjs and Im building a game which will involve players joining at random points in time,I'd like to confirm if my coding approach is right, As you can see below, each player is created using add_hero() instead of create() 13 var add_hero = function(name, channel, ts){ 14 heroes[name] = {}; 15 heroes[name]['name'] = name; 16 heroes[name]['id'] = hero_count; 17 heroes[name]['connected'] = 1; 18 heroes[name]['last_input_ts'] = ts; 19 20 heroes[name] = games.add.sprite(0, 0, 'hero_' + hero_count ); 21 22 heroes[name].body.collideWorldBounds = true; 23 heroes[name].body.bounce.y = 0.3; 24 heroes[name].body.bounce.x = 0.3; 25 26 heroes[name].body.velocity.x = 0; 27 heroes[name].body.velocity.y = 0; 28 heroes[name].body.angularVelocity = 0; 29 30 } 31 if I need to check for collision detection or any other task that will involves looping through all players/items, would this be right? function update() { for var hero in heroes{ game.physics.overlap(hero, gifts, collect_gift, null, this); }....... Thanks for any pointers/advice/help Quote Link to comment Share on other sites More sharing options...
STuFF Posted January 12, 2014 Share Posted January 12, 2014 Uou should use a "group" for all of your player. Phaser's collide method can check collisions for the while group. Then you only have to add your players to that group. (there are examples of using groups) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.