zsumair Posted November 17, 2014 Share Posted November 17, 2014 Hi All, I am newbie in Phaser. I need to generate obstacles or objects in player path on the horizontal . but i am confused as when i am trying the objects are appearing sometimes on top and then bottom. I just want it along x (i.e horizontal). Please help Thanks Link to comment Share on other sites More sharing options...
lewster32 Posted November 17, 2014 Share Posted November 17, 2014 We'd need to see the code - could you upload your current demo, or (ideally) create a test case on jsFiddle/Codepen please? Link to comment Share on other sites More sharing options...
zsumair Posted November 17, 2014 Author Share Posted November 17, 2014 Here's the code Lewster // Create Function create: function() { game.stage.backgroundColor='#e34221'; game.physics.startSystem(Phaser.Physics.ARCADE); this.myWorld=game.add.group(); this.myWorld.enableBody=true; //group create var ground=this.myWorld.create(0,game.world.height-64,'ground'); ground.scale.setTo(2,2); ground.body.immovable=true; // Creating group of Boxes this.boxes = game.add.group(); this.boxes.enableBody=true; this.boxes.createMultiple(20,'box'); // Player Sprite added to the screen this.player = game.add.sprite(0, 250,'player'); game.physics.arcade.enable(this.player); this.player.body.bounce.y = 0.25; this.player.body.gravity.y = 980; this.player.body.collideWorldBounds = true; // Add animations or walk of player animations.add(name, frames, frame rate, loop); this.player.animations.add('right',[3, 4, 5],10,true); this.player.animations.add('left',[9, 10, 11],10,true); this.player.frame=6; this.cursors = this.input.keyboard.createCursorKeys(); // Timer that call row of Boxes every 1.5 seconds this.timer=this.game.time.events.loop(1500,this.addRowOfBoxes,this); }, //Update Function update: function() { game.physics.arcade.collide(this.player,this.myWorld); this.player.body.velocity.x = 0; if (this.cursors.right.isDown) { this.player.body.velocity.x = 200; this.player.animations.play('right'); } else if (this.cursors.left.isDown) { this.player.body.velocity.x = -200; this.player.animations.play('left'); } else { this.player.animations.stop(); this.player.frame = 6; } // // Allow player to jump if player touching the ground. if (this.cursors.up.isDown && this.player.body.touching.down) { this.player.body.velocity.y = -500; } }, //Custom Functions //Add one Box addOneBox : function(x,y){ var box = this.boxes.getFirstDead(); box.reset(x,y); box.body.velocity.x=-200; box.checkWorldBounds=true; box.outOfBoundsKill=true; }, //Add row of Pipes addRowOfBoxes : function() { var hole = Math.floor(Math.random()*4); for (var i = 0; i < 8; i++) if (i != hole && i != hole +1) this.addOneBox(470, i*50); },}; Link to comment Share on other sites More sharing options...
zsumair Posted December 3, 2014 Author Share Posted December 3, 2014 Wow 228 views on this post.. and more than two weeks passed..but no one to help here..great community not even the moderators bother to comment or even people don't even try.. Link to comment Share on other sites More sharing options...
lewster32 Posted December 3, 2014 Share Posted December 3, 2014 These forums are a fantastic resource for learning both Phaser and JavaScript in general, typically from people who are in many cases highly skilled professionals working with JavaScript full time and providing support in what little spare time they get. However as hard as we try to answer (and hopefully solve) every question that's asked, some slip the net. As I said, the best way to get your problems solved is to create a test case in jsFiddle or Codepen which demonstrates just your issue clearly. If you can provide that, or if you could actually upload your game so we can see the problem happening, I'm pretty sure myself or one of the many other clued-up individuals on the forums would be able to solve it quickly, or at least give you some good steering towards the answer. Unfortunately, simply dumping in your code like this makes it difficult to work out what's going on, and most will see this and feel it'd require too much effort to turn this into a working test case to debug. Link to comment Share on other sites More sharing options...
xerver Posted December 3, 2014 Share Posted December 3, 2014 Wow 228 views on this post.. and more than two weeks passed..but no one to help here..great community not even the moderators bother to comment or even people don't even try.. I'd be happy to respond: You copy-pasted your code into a text field with no code highlighting and no formatting; therefore I put in as much effort as you did, none. If you copy paste code *at least* format it so we can read it. You should just give us a running example though so we can start debugging. The easier it is to help you (directly related to the effort you put in to making it easy) the more people will help you. When I see a copy-paste of a bunch of code straight into the post that looks like rubish I just move on and never look back. I had to stop this time because your above post was just so rude and entitled. Link to comment Share on other sites More sharing options...
zsumair Posted December 4, 2014 Author Share Posted December 4, 2014 @Lewster am sorry to have simply dumped the code i thought the comments would've helped..i'll create a test case and post the link here. Link to comment Share on other sites More sharing options...
zsumair Posted December 4, 2014 Author Share Posted December 4, 2014 @xerver i wasn't trying to be rude. that was just my astonishment about the replies on the forum. What you are saying seems rude. And it would be a big help to others if you **atleast** tell people to format the code or create a test case instead of just moving on.I don't think overlooking the question if you see copy pasted code can help anyone in any regard. Its just a suggestion am giving not in a rude way Link to comment Share on other sites More sharing options...
Recommended Posts