abdul Posted July 9, 2014 Share Posted July 9, 2014 Hii am newbie in phaser , i am making a game in which i want that pieces of woods fall from sky randomly, or move up towards sky, how can i perform this job, can anyone help me regarding this problem.thanx Link to comment Share on other sites More sharing options...
lewster32 Posted July 9, 2014 Share Posted July 9, 2014 You probably want to use a particle emitter for this kind of thing, see this example: http://examples.phaser.io/_site/view_full.html?d=particles&f=snow.js&t=snow Link to comment Share on other sites More sharing options...
abdul Posted July 10, 2014 Author Share Posted July 10, 2014 I have one player . When game starts player create in the middle of bottom. I want that a series of woods with some time gap move up, in the left and right of my player.so the function which I am using isvar woodTime=0;this is in create function woods2 = game.add.group(); woods2.enableBody = true; woods2.physicsBodyType = Phaser.Physics.ARCADE; woods2.createMultiple(3, 'wood'); woods2.setAll('anchor.x', 0.5); woods2.setAll('anchor.y', 1); woods2.setAll('outOfBoundsKill', true); woods2.setAll('checkWorldBounds', true);then i have function for woodsfunction woodsMovingUp() { if (game.time.now > woodTime) { wood = woods.getFirstExists(false); if (wood) { wood.reset(80, game.world.height - 410); wood.body.velocity.y = 70; wood.body.immovable = true; game.physics.arcade.collide(mummy, wood); woodTime = game.time.now + 2000; } } }I am using two functions of same content for left woods and right woods like this. in my update functionsec = new Date().getSeconds(); if (sec % 0.5 == 0) woodsMovingUp2(); if (sec % 0.2 == 0) woodsMovingUp();it is working but not good.. I want that both functions works parallel.. but they are not. so plz help me here.. I am very confused..or may be i am not using correct functions..I want that first, left side wood come, my player jumps on it then right side wood then again on left and so on in zig zag position... I am also using star function. .. but same problem, there is no right place to call it. because if i call it before wood functions then only stars function works, woodMovingUP() doesn't work......plz help me... Link to comment Share on other sites More sharing options...
lewster32 Posted July 10, 2014 Share Posted July 10, 2014 I think I'd need to see this running to be sure of what's going wrong. Any chance you could upload it? Link to comment Share on other sites More sharing options...
ZoomBox Posted July 10, 2014 Share Posted July 10, 2014 Give us all your code and how it actually behaves. In the sample of code you gave us, it looks like you only have one group of sprites so you're working on the same group in both functions ? Link to comment Share on other sites More sharing options...
abdul Posted July 10, 2014 Author Share Posted July 10, 2014 game.zip I have upload the files, plz check Link to comment Share on other sites More sharing options...
lewster32 Posted July 10, 2014 Share Posted July 10, 2014 Sorry I'm still really having trouble working out what you're trying to do... when I run this, the wood falls on the left and right alternately in the zig-zag pattern you describe. It seems to me like you may just be going about it in a confusing way. Maybe what you need is a 'fall' function which cycles through the possible actions at a specified interval, like this:var fallInterval = 2000;var fallIndex = 0;var fallTypes = ["left", "right", "star"];function doFall() { if (game.time.now > fallTime) { fallTime = game.time.now + fallInterval; // increase the index, and make sure it wraps around to 0 fallIndex = (fallIndex + 1) % fallTypes.length; var fallType = fallTypes[fallIndex]; switch(fallType) { case "left": // ... make the left log fall here... break; case "right": // ... make the right log fall here... break; case "star": // ... make the star fall here... break; } }}function update() { doFall();}Doing it this way means you will get a log on the left, then a 2 second delay, then a log on the right, then a 2 second delay, then a star, then a delay, then it will repeat. You can then configure the pattern, add more, remove steps and so on. Is this the kind of thing you mean? Link to comment Share on other sites More sharing options...
abdul Posted July 10, 2014 Author Share Posted July 10, 2014 thanx alot sir...it is working good...but there is little conflict ... on some fix fallInterval it does not work, but no problem ... your code helps me alot and solve my problemthere is one thing more I want that if my player is on right side wood and he jumps on the right side boundry, instead of going invisible beyond the boundry , he should appear on the left side of screen... is there any tutorial regarding this..then plz guide me.. Link to comment Share on other sites More sharing options...
lewster32 Posted July 10, 2014 Share Posted July 10, 2014 What you're looking for is 'wrapping' - see this: http://docs.phaser.io/Phaser.World.html#wrap Link to comment Share on other sites More sharing options...
abdul Posted July 11, 2014 Author Share Posted July 11, 2014 thanx alot sir, wrapping slove my problem...but there is another problem which is not solving... I only want to wrap the world on horizontal axis, not the vertical axis.. here I am writing 'false' in the arg of wrap vertical axis,game.world.wrap(mummy,0,false,true,false);but it doesn't work.. Link to comment Share on other sites More sharing options...
lewster32 Posted July 11, 2014 Share Posted July 11, 2014 Make sure you're using Phaser 2.0.6 which just came out last night, as this is a newly added feature. Link to comment Share on other sites More sharing options...
abdul Posted July 11, 2014 Author Share Posted July 11, 2014 I was using old version of phasernow with new version it is working finethanx sir lewster32 1 Link to comment Share on other sites More sharing options...
abdul Posted July 11, 2014 Author Share Posted July 11, 2014 I am trying to collide group vs group . But no collision is going on. Both have velocity in same direction.game.physics.arcade.collide(diamond, wood);Sir, is there any other way to perform this? Link to comment Share on other sites More sharing options...
lewster32 Posted July 11, 2014 Share Posted July 11, 2014 Try adding the following in your render function to ensure the bodies are working and in the right places:function render() { diamond.forEachAlive(function(d) { game.debug.body(d); }, this); wood.forEachAlive(function(w) { game.debug.body(w); }, this);} abdul 1 Link to comment Share on other sites More sharing options...
abdul Posted July 11, 2014 Author Share Posted July 11, 2014 sir error comesi.e Uncaught TypeError: Cannot read property 'forEachAlive' of undefined Link to comment Share on other sites More sharing options...
lewster32 Posted July 11, 2014 Share Posted July 11, 2014 One of these isn't a group then. You may need to go back through your code and ensure both are set up as groups, and you're not overwriting the 'diamond' or 'wood' variables anywhere. If one or both are not meant to be groups, then you can write the render function like this:function render() { game.debug.body(diamond); game.debug.body(wood);} abdul 1 Link to comment Share on other sites More sharing options...
abdul Posted July 11, 2014 Author Share Posted July 11, 2014 yes sir you are right, sir there was little bit 's' mistake in spelling... It is working but sir after using this a boundry around my objects is showing ,like some one wrap a piece of shaded glass around my objects, how can I remove this? Link to comment Share on other sites More sharing options...
lewster32 Posted July 11, 2014 Share Posted July 11, 2014 Just remove the functions, or comment them out. They're just so you can see the collision rectangle itself. The reason for doing this in the first place was so you could see that the objects did indeed have physics bodies and that the collision rectangle was the correct size. abdul 1 Link to comment Share on other sites More sharing options...
abdul Posted July 11, 2014 Author Share Posted July 11, 2014 everything is working fine, but stars do not collide with woods, plane and cloud.... even the function and properties of stars are same as the diamonds are and diamonds perform everything.In create function stars = game.add.group(); stars.enableBody = true; stars.physicsBodyType= Phaser.Physics.ARCADE; stars.createMultiple(30, 'star'); stars.setAll('outOfBoundsKill', true); stars.setAll('checkWorldBounds', true);In update functiongame.physics.arcade.collide(stars, plane);game.physics.arcade.collide(stars, woods);game.physics.arcade.collide(stars, woods2);but they are not working..If there is any error then plz help me.. Link to comment Share on other sites More sharing options...
lewster32 Posted July 11, 2014 Share Posted July 11, 2014 That's very odd, not sure what's going on there... if you enable the debug.body functions in render do stars have a visible rectangular body? Link to comment Share on other sites More sharing options...
abdul Posted July 12, 2014 Author Share Posted July 12, 2014 When i enable debug.body functions in render, nothing happens to stars, but when I enablestars.forEachAlive(function(s) { game.debug.body(s); }, this);then stars have a visible rectangular body but no collision....... Link to comment Share on other sites More sharing options...
lewster32 Posted July 12, 2014 Share Posted July 12, 2014 I can't really say what's going on here, there's nothing obviously wrong from the code you've shown me. Your best bet is to disable all other collisions and just try to get stars colliding with something as a test. When trying to debug, try to establish a process of elimination, removing all external factors and just testing the bare minimum thing you need. It often becomes obvious what the problem is then. Link to comment Share on other sites More sharing options...
Recommended Posts