Jump to content

Search the Community

Showing results for tags 'polylines'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 2 results

  1. I am testing Phaser's polyline handling for tilesets in a platformer. Everything works as expected for flat surfaces, and undersides of surfaces, but there's a strange effect. When the character jumps onto the surface of the a slope of a polyline the character bounces around like it's still jumping. After a bounce or two the character settles down on the sloped surface and slides down a little. I'm using a json tilemap. There's a few unused variables because of testing, but this is the working code. function preload () { game.load.spritesheet('player', 'assets/player.png', 80, 50, 4); game.load.image('tiles1', 'assets/tiles1.png'); // loading the tileset image game.load.tilemap('map', 'assets/tiles2.json', null, Phaser.Tilemap.TILED_JSON); // loading the tilemap}function create () { //game.world.setBounds(0, 0, 1600, 1200); // Enable p2 physics game.physics.startSystem(Phaser.Physics.P2JS); // Turn on impact events for the world, without this we get no collision callbacks game.physics.p2.setImpactEvents(true); //gravity game.physics.p2.gravity.y = 300; //bounce //game.physics.p2.restitution = 0.1; map = game.add.tilemap("map"); map.addTilesetImage('tiles1'); // Preloaded tileset layer = map.createLayer('Tile Layer 1'); // This is the default name of the first layer in Tiled layer.resizeWorld(); // Sets the world size to match the size of this layer. game.physics.p2.convertCollisionObjects(map, "ob1"); //map.setCollisionByExclusion([0], true, layer, true) //game.physics.p2.convertTilemap(map, layer); game.physics.p2.setBoundsToWorld(true, true, true, true, false); player = game.add.sprite(game.world.centerX, game.world.centerY, 'player'); player.anchor.setTo(0.5, 0.5); player.animations.add("run"); game.camera.follow(player); game.physics.p2.enable(player); player.body.fixedRotation = true; //player.body.mass = 1.5; cursors = game.input.keyboard.createCursorKeys();}var jumped = false;function update(){ var jump = checkIfCanJump(player), run = jump; if(!run && (player.body.velocity.y > -250 && player.body.velocity.y < 300)){ if(cursors.left.isDown) player.body.velocity.x = -200; else if(cursors.right.isDown) player.body.velocity.x = 200; else if(!jumped) player.body.velocity.x = 0; jumped = true; } if(run){ player.body.velocity.x = 0; jumped = false; } if (cursors.left.isDown && run){ player.body.velocity.x = -250; player.animations.play("run");//, 10, true); } else if (cursors.right.isDown && run) { player.body.velocity.x = 250; player.animations.play("run", 10, true); }else{ player.animations.stop(); } if(cursors.up.isDown && jump){// && player.body.touching.down){ player.body.velocity.y = -300; }}function checkIfCanJump(player) { var yAxis = p2.vec2.fromValues(0, 1); var result = false; for (var i = 0; i < game.physics.p2.world.narrowphase.contactEquations.length; i++) { var c = game.physics.p2.world.narrowphase.contactEquations[i]; if (c.bodyA === player.body.data || c.bodyB === player.body.data) { var d = p2.vec2.dot(c.normalA, yAxis); // Normal dot Y-axis if (c.bodyA === player.body.data) d *= -1; if (d > 0.5) result = true; } } return result;}
  2. according to the source: http://docs.phaser.io/World.js.html#sunlight-1-line-1461 convertCollisionObjects gets the properties // properties: json.layers[i].objects[v].properties,but does not do anything with it.. createBody would accept "options" int the 5th field but is using them to create the polygon. http://docs.phaser.io/World.js.html#sunlight-1-line-1378 var result = body.addPolygon(options, data);so this is not the way to go.. (because addPolygon is only taking 3 special options .. so i instead of using this (real game example:) collisionareas = game.physics.p2.convertCollisionObjects(map,"collisionareas");i am now using this: var collisionareas = []; var layer = "collisionareas" for (var i = 0, len = map.collision[layer].length; i < len; i++) { var object = map.collision[layer][i]; var body = game.physics.p2.createBody(object.x, object.y, 0, true, {} , object.polyline); body.properties = object.properties; if (body){ collisionareas.push(body);} }then i am able to access the properties set in tiled on my collisonareas (polylines) for (i=0; i<collisionareas.length; i++){ if (collisionareas[i].properties.action == 'ramp'){ collisionareas[i].onBeginContact.add(jumpOnRamp, this); } }now my question is: did i NOT see the obvious way how to do this or is this just not implementet (yet) and.. is this ok to do this or is it dangerous to use something like "body.properties" because it is used somewhere else and will cause me troubles later on? thx in advance!
×
×
  • Create New...