Tenshi Posted January 27, 2015 Share Posted January 27, 2015 Hello,I just started to learn PHASER.So I want to create platformer game like STARSTRUCK ( http://dev.phaser.io/examples/games/starstruck# ). But in example map consists of rectangles excluding this place: This place has no body. So character can stay IN this triangle.But my map must be freeform(not just rectangles or triangles). Is it possible in phaser?I tried to use the image with invisible part. But it does not work becouse invisible part has a body. Link to comment Share on other sites More sharing options...
Tenshi Posted January 28, 2015 Author Share Posted January 28, 2015 Bump. Link to comment Share on other sites More sharing options...
mrdotb Posted January 28, 2015 Share Posted January 28, 2015 Show some code. Link to comment Share on other sites More sharing options...
valueerror Posted January 28, 2015 Share Posted January 28, 2015 you need to use p2 physics instead of arcade and then work with Polygons.. you can use tiled editor for example to paint your map and create poligons with the polyline tool too... there are already 100 posts in this forum that cover this topic.. search for polylines or better.. slanted tiles or something similar Link to comment Share on other sites More sharing options...
Tenshi Posted January 28, 2015 Author Share Posted January 28, 2015 Show some code.All code is from first example for phaser. And I dont understand how it can help.<!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Phaser - Making your first game, part 1</title> <script type="text/javascript" src="js/phaser.min.js"></script> <style type="text/css"> body { margin: 0; } </style></head><body><script type="text/javascript">var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });function preload() { game . load . image ( 'rock' , 'assets/rock.png' ) ; game . load . image ( 'sky' , 'assets/sky.png' ) ; game . load . image ( 'ground' , 'assets/platform.png' ) ; game . load . image ( 'star' , 'assets/star.png' ) ; game . load . spritesheet ( 'dude' , 'assets/dude.png' , 32 , 48 ) ; }function create() { game . physics . startSystem ( Phaser . Physics . ARCADE ) ; // A simple background for our game //game . add . sprite ( 0 , 0 , 'sky' ) ; game.add.tileSprite(0, 0, 1920, 600, 'sky'); game.world.setBounds(0, 0, 1920, 600); // The platforms group contains the ground and the 2 ledges we can jump on platforms = game . add . group ( ) ; // We will enable physics for any object that is created in this group platforms . enableBody = true ; // Here we create the ground. var ground = platforms . create ( 0 , game . world . height - 64 , 'ground' ) ; ground . scale . setTo ( 5 , 2 ) ; ground . body . immovable = true ; var rock = platforms . create ( 80 , 400 , 'rock' ) ; rock . scale . setTo ( 5 , 2 ) ; rock . body . immovable = true ; // Now let's create two ledges var ledge = platforms . create ( 400 , 400 , 'ground' ) ; ledge . body . immovable = true ; ledge = platforms . create ( - 150 , 250 , 'ground' ) ; ledge . body . immovable = true ; // The player and its settings player = game . add . sprite ( 32 , game . world . height - 150 , 'dude' ) ; // We need to enable physics on the player game . physics . arcade . enable ( player ) ; // Player physics properties. Give the little guy a slight bounce. player . body . bounce . y = 0 ; player . body . gravity . y = 2000 ; player . body . collideWorldBounds = true ; // Our two animations, walking left and right. player . animations . add ( 'left' , [ 0 , 1 , 2 , 3 ] , 10 , true ) ; player . animations . add ( 'right' , [ 5 , 6 , 7 , 8 ] , 10 , true ) ; game.camera.follow(player);}function update() {game . physics . arcade . collide ( player , platforms ) ;cursors = game . input . keyboard . createCursorKeys ( ) ; // Reset the players velocity (movement) player . body . velocity . x = 0 ; if ( cursors . left . isDown && player . body . touching . down ) { // Move to the left player . body . velocity . x = - 150 ; player . animations . play ( 'left' ) ; } else if ( cursors . right . isDown && player . body . touching . down ) { // Move to the right player . body . velocity . x = 150 ; player . animations . play ( 'right' ) ; } else { // Stand still player . animations . stop ( ) ; player . frame = 4 ; } if (player . body . touching . down) { player . body . gravity . x = 0 ; } // Allow the player to jump if they are touching the ground. if ( cursors . up . isDown && player . body . touching . down) { player . body . velocity . y = - 1000 ; } if ( cursors . up . isDown && player . body . touching . down && cursors . right . isDown) { player . body . gravity . x = 20000 ; player . body . velocity . y = - 1000 ; } if ( cursors . up . isDown && player . body . touching . down && cursors . left . isDown) { player . body . gravity . x = -20000 ; player . body . velocity . y = - 1000 ; } } </script></body></html> Link to comment Share on other sites More sharing options...
Tenshi Posted January 28, 2015 Author Share Posted January 28, 2015 you need to use p2 physics instead of arcade and then work with Polygons.. you can use tiled editor for example to paint your map and create poligons with the polyline tool too... there are already 100 posts in this forum that cover this topic.. search for polylines or better.. slanted tiles or something similarThx. I found what I need. Link to comment Share on other sites More sharing options...
Recommended Posts