Jump to content

tween body solutions. platform moving. platform from tiledmap


nak3ddogs
 Share

Recommended Posts

Hi! First of all sry for my terrible english.

I done a perfect method for me to move platforms with tween and i read the platforms's properties from the tiledmap json.

The problem is coz i tween the sprite.x it is a repositioning and not a moving. But i wont tween the velocity coz this work pixel perfectly and i would use the quadratic easing

I tryed this code but i not finished yet and it is not perfect.

Somebody have a idea for better solution?

My idea: make a invisible point tween this object and use acceleratetoobject method. I not tryed yet

 

this.platform5group = this.game.add.group();this.platform5group.enableBody = true;this.platform5group.physicsBodyType = Phaser.Physics.ARCADE;this.game.map.createFromObjects('objects', 786, 'platform5', null, true, false, this.platform5group);this.platform5group.forEachExists(function(platform){if (typeof platform.xmove === 'undefined') { platform.xmove = 0; }if (typeof platform.ymove === 'undefined') { platform.ymove = 0; }if (typeof platform.blink === 'undefined') { platform.blink = false; }if (typeof platform.b_delay === 'undefined') { platform.b_delay = 0; }if (typeof platform.b_vis === 'undefined') { platform.b_vis = 1500; }if (typeof platform.b_hid === 'undefined') { platform.b_hid = 1500; }if (typeof platform.dest === 'undefined') { platform.dest = false; }if (typeof platform.d_out === 'undefined') { platform.d_out = 2000; }if (typeof platform.d_in === 'undefined') { platform.d_in = 2000; }if (typeof platform.allface === 'undefined') { platform.allface = false; }if (typeof platform.wait === 'undefined') { platform.wait = 0; }if (typeof platform.speed === 'undefined') { platform.speed = 1; }platform.tween_blink_out = null;platform.tween_blink_in = null;platform.body.immovable = true;if (platform.allface == false) {platform.body.checkCollision.right = false;platform.body.checkCollision.down = false;platform.body.checkCollision.left = false;}if (platform.xmove != 0 || platform.ymove != 0){this.game.add.tween(platform).to({x:platform.x+(platform.xmove*24), y:platform.y+(platform.ymove*24)}, Math.abs(platform.xmove+platform.ymove)*50/platform.speed, Phaser.Easing.Quadratic.InOut, true, platform.wait, Number.MAX_VALUE, true);}if (platform.blink) {platform.tween_blink_out = this.game.add.tween(platform);platform.tween_blink_out.to({alpha: 0}, 400, Phaser.Easing.Quadratic.Out, false, platform.b_vis, false).onComplete.add(function(){platform.tween_blink_in.start();platform.body.enable = false;},this);platform.tween_blink_in = this.game.add.tween(platform);platform.tween_blink_in.to({alpha: 1}, 400, Phaser.Easing.Quadratic.Out, false, platform.b_hid, false).onComplete.add(function(){platform.tween_blink_out.start();platform.body.enable = true;},this);platform.tween_blink_in.start();};},this);}, //end of createupdate: function () {this.game.physics.arcade.collide(this.game.player.sprite, this.platform3group);this.game.physics.arcade.collide(this.game.player.coinGroup, this.platform3group);this.game.physics.arcade.collide(this.game.player.sprite, this.platform5group, function(player, platform){player.x += platform.x - this.contactPoint;this.contactPoint = platform.x;}, null, this);this.game.physics.arcade.collide(this.game.player.coinGroup, this.platform5group);}, //end of update
Link to comment
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...
 Share

  • Recently Browsing   0 members

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