khleug35 Posted September 30, 2018 Share Posted September 30, 2018 Hello everyone, I am beginner of panda2. I would like to create a platformer game like Kuru Panda, so I download panda2-template-platformer.zip to start my project. and want to create a float platform that can move right to left or left to right on game like the following demo 2:26 but I am not successful to create that, the player can't move when drive on the float platform game.createClass('Float_platformer', { init: function() { this.float_platformer = new game.Sprite('float_platformer.png'); this.float_platformer.anchorCenter(); this.float_platformer.addTo(game.scene.container); this.body = new game.Body(); this.body.mass = 0; this.body.position.x = 1260; this.body.position.y = 1460; this.body.collisionGroup = 2; var shape = new game.Rectangle(); shape.width = this.float_platformer.width; shape.height = this.float_platformer.height; this.body.addShape(shape); this.body.static = true; this.body.addTo(game.scene.world); game.Tween.add(this.body.position, { x: 1560 }, 2000, { easing: 'Quadratic.InOut', repeat: Infinity, yoyo: true }).start(); }, update: function() { this.float_platformer.position.x = this.body.position.x; this.float_platformer.position.y = this.body.position.y; } }); game.createClass('Player', { ..... collide2: function(other) { if (other.collisionGroup === 2) { this.body.velocity.x = 200; } }, .... )}; any tips or idea??? Thank you very much Quote Link to comment Share on other sites More sharing options...
Wolfsbane Posted September 30, 2018 Share Posted September 30, 2018 [snip player collision] collide2: function(other) { if (other.collisionGroup === 2) { this.body.velocity.x = 200; } }, I'd probably change this to just set a flag. e.g. this.onPlatform = true. this.myPlatform = other; //let's store a reference to the other. Then in update() you can try some tricks to move the player. //normal move left/right code, update x coordinates, etc. if ( this.onPlatform ) { if ( other !== undefined ) { this.body.x += other.body.xVelocity; } } You could also do the update in the platform itself. Like: update: function() { if ( playerObj.onPlatfrom) { playerObj.x += ( this.float_platformer.position.x - this.body.position.x); } this.float_platformer.position.x = this.body.position.x; this.float_platformer.position.y = this.body.position.y; } Something like this? khleug35 and Ninjadoodle 2 Quote Link to comment Share on other sites More sharing options...
khleug35 Posted October 1, 2018 Author Share Posted October 1, 2018 Oh, Many Thank you for your help @Wolfsbane Finally I work on it !!!!!!!! Really Really Thanks !!!!!!!! firstly I added this code on player class collide: function(body, dir) { if (body.collisionGroup === 2) { this.onPlatform = true; // default is false this.myPlatform = body; }else{ this.onPlatform = false; } and add this code on float platform update function update: function() { if (game.scene.player.onPlatform) { game.scene.player.body.position.x -= ( this.float_platformer.position.x - this.body.position.x); } this.float_platformer.position.x = this.body.position.x; this.float_platformer.position.y = this.body.position.y; } It work!!!! Thanks again, for the help on this , have a nice day Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Wolfsbane Posted October 1, 2018 Share Posted October 1, 2018 Great! Look forward to seeing what you make. ? khleug35 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.