Jump to content

free falling objects


abdul
 Share

Recommended Posts

Hi

i 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

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 is

var 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 woods

function 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 function

sec = 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

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

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 problem

there 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

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

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

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);}
Link to comment
Share on other sites

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

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 function

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

When i enable debug.body functions in render, nothing happens to stars, but when I enable

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

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

 Share

  • Recently Browsing   0 members

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