Ansimuz Posted November 10, 2017 Share Posted November 10, 2017 I'm trying to change the velocity of an object with a callback from "setTileIndexCallback" but with no luck. I can read its body velocity but cannot set it. Slug = function (game, x, y) { x *= 16; y *= 16; Phaser.Sprite.call(this, game, x, y, "atlas", "slug/slug-1"); this.animations.add('crawl', Phaser.Animation.generateFrameNames('slug/slug-', 1, 4, '', 0), 10, true); this.animations.play("crawl"); this.anchor.setTo(0.5); game.physics.arcade.enable(this); this.body.setSize(20, 11, 7, 10); this.body.gravity.y = 500; this.body.velocity.x = 40; this.body.bounce.x = 1; globalMap.setTileIndexCallback(3, function(){ console.log(this.body.velocity.x); this.body.velocity.y = -50; }, this); } Slug.prototype = Object.create(Phaser.Sprite.prototype); Slug.prototype.constructor = Slug; Link to comment Share on other sites More sharing options...
Ansimuz Posted November 10, 2017 Author Share Posted November 10, 2017 I just figure it out! I put the setTileIndexCallback outside the SlugPrototype and inside the create state. As I read here: http://www.html5gamedevs.com/topic/1471-how-to-handle-collision-between-sprite-and-tilemap/ samme 1 Link to comment Share on other sites More sharing options...
Recommended Posts