Jump to content

Phaser isometric walk problem


aozalp
 Share

Recommended Posts

Hello my players how to move it in the right isometric does not move in a proper manner?

 

 

DEMO: http://www.ahmetozalp.net/demo/PokeCity/

 

It will act as the library

http://www.travisojs.com/examples/example1/

 

 

Quote

	var pokemon = function (game) { };
	
        var isoGroup, water = [],cursorPos, cursor, player, x_point;
		
        pokemon.game = {
            preload: function () {
                game.time.advancedTiming = true;
                game.debug.renderShadow = false;
                game.stage.disableVisibilityChange = false;

                game.plugins.add(new Phaser.Plugin.Isometric(game));

                game.load.atlasJSONHash('tileset', 'img/tile.png', 'json/tilemap.json');
                game.load.spritesheet('player', 'img/dude.png', 32,73);

                
                game.iso.anchor.setTo(0.5, 0.2);
				
				
				game.physics.startSystem(Phaser.Plugin.Isometric.ISOARCADE);
            },
            create: function () {
                game.input.addPointer();
                isoGroup = game.add.group();

                isoGroup.enableBody = true;
                isoGroup.physicsBodyType = Phaser.Plugin.Isometric.ISOARCADE;


                var tileArray = [];
                tileArray[0] = 'water';
                tileArray[1] = 'sand';
                tileArray[2] = 'grass';
                tileArray[3] = 'stone';
                tileArray[4] = 'wood';
                tileArray[5] = 'watersand';
                tileArray[6] = 'grasssand';
                tileArray[7] = 'sandstone';
                tileArray[8] = 'bush1';
                tileArray[9] = 'bush2';
                tileArray[10] = 'mushroom';
                tileArray[11] = 'wall';
                tileArray[12] = 'window';

               var tiles = [
					2, 2, 1, 1, 4, 4, 1, 6, 2, 10, 2,
					2, 6, 1, 0, 4, 4, 0, 0, 2, 2, 2,
					6, 1, 0, 0, 4, 4, 0, 0, 8, 8, 2,
					0, 0, 0, 0, 4, 4, 0, 0, 0, 9, 2,
					0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0,
					0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0,
					0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0,
					0, 0, 0, 0, 4, 4, 0, 0, 0, 0, 0,
					11, 11, 11, 11, 3, 3, 11, 11, 11, 11, 11,
					3, 7, 3, 3, 3, 3, 3, 3, 7, 3, 3,
					7, 1, 7, 7, 3, 3, 7, 7, 1, 1, 7
				];

				this.spawnTiles(tiles, tileArray);
				
				cursorPos = new Phaser.Plugin.Isometric.Point3();
				

				player = game.add.isoSprite(32, 32, -40, 'player', 0, isoGroup);
				player.anchor.set(0.5);
				game.physics.isoArcade.enable(player);
				game.physics.arcade.enable(player);
				player.body.collideWorldBounds = true;
				game.camera.follow(player);
				player.body.gravity.z = -900;


				this.cursors = game.input.keyboard.createCursorKeys();



				isoGroup.enableBody = true;

            },
            update: function () {
				game.iso.simpleSort(isoGroup);
				game.physics.isoArcade.collide(isoGroup);

				// collision detection?
				game.physics.isoArcade.collide(isoGroup);

                //* player
				var speed = 73;
				if (this.cursors.up.isDown) {
				  this.playerMovement(0, -speed);
				  player.animations.play('up');
				} else if (this.cursors.down.isDown) {
				  this.playerMovement(0, speed);
				  player.animations.play('down');
				} else if (this.cursors.left.isDown) {
				  this.playerMovement(-speed, 0);
				  player.animations.play('left');
				} else if (this.cursors.right.isDown) {
				  this.playerMovement(speed, 0);
				  player.animations.play('right');
				} else if (game.input.mousePointer.isDown) {
				  game.input.mouse_x = game.input.mousePointer.position['x'];
				  game.input.mouse_y = game.input.mousePointer.position['y'];
				  game.input.mouse_z = game.input.mousePointer.position['z'];
				} else if (
				  Math.abs(player.position.x - game.input.mouse_x) > 5 ||
				  Math.abs(player.position.y - game.input.mouse_y) > 5
				) {
				  game.physics.arcade.moveToXY(player, game.input.mouse_x, game.input.mouse_y, speed);
				} else {
				  this.playerMovement(0,0);
				  player.animations.stop();
				}

			
				
				
				game.iso.unproject(game.input.activePointer.position, cursorPos);

				isoGroup.forEach(function (tile) {
				  var inBounds = tile.isoBounds.containsXY(cursorPos.x, cursorPos.y);
				  if (!tile.selected && inBounds) {
					  tile.selected = true;
					  tile.tint = 0x86bfda;
				  }
				  else if (tile.selected && !inBounds) {
					  tile.selected = false;
					  tile.tint = 0xffffff;
				  }
				});

            },
            render: function () {
                isoGroup.forEach(function (tile) {
                    //game.debug.body(tile, 'rgba(189, 221, 235, 0.6)', false);
                 });
                game.debug.text("FPS: "+game.time.fps || '--', 5, 14, "#a7aebe");
            },
			spawnTiles: function (tiles, tileArray) {
				var size = 32;

                var i = 0, tile;
				for (var y = size; y <= game.physics.isoArcade.bounds.frontY - size; y += size) {
					for (var x = size; x <= game.physics.isoArcade.bounds.frontX - size; x += size) {
						
						tile = game.add.isoSprite(x, y, tileArray[tiles[i]].match("water") ? 0 : game.rnd.pick([0]), 'tileset', tileArray[tiles[i]], isoGroup);
						tile.anchor.set(0.5, 0);

						
						game.physics.isoArcade.enable(tile);
						tile.body.immovable = true;
			
						if (tiles[i] <= 10 && (tiles[i] < 5 || tiles[i] > 6)) {
							tile.scale.x = game.rnd.pick([-1, 1]);
						}
						if (tiles[i] === 11) {
							tile.isoZ += 45;
						}
						i++;
					}
				}
			
			},
			playerMovement: function(x, y) {
				var x = x || 0;
				var y = y || 0;

				player.body.velocity.x = x;
				player.body.velocity.y = y;	
			}		

        };

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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