Jump to content

How do I use setTileIndexCallback?


What?
 Share

Recommended Posts

  • 2 weeks later...

It's not working. Is it possible to make a tile kill the player when they touch it, for example?

 

here's my code:

var loderunner = loderunner || {};loderunner.Game = function(){};loderunner.Game.prototype.preload = function(){	this.game.time.advancedTiming = true;	this.game.physics.startSystem(Phaser.Physics.ARCADE);    this.load.spritesheet('dude', 'assets/dude.png', 64, 64);    this.load.tilemap('level', 'assets/templevel.json', null, Phaser.Tilemap.TILED_JSON);    this.load.image('tiles', 'assets/temptiles.png');};loderunner.Game.prototype.create = function(){		this.map = this.game.add.tilemap('level');	this.map.setTileIndexCallback(0, this.haha, this);	this.map.addTilesetImage('temptiles', 'tiles');	this.blockedLayer = this.map.createLayer('blockedLayer');	this.map.setCollisionBetween(1, 1000, true, 'blockedLayer');	this.blockedLayer.resizeWorld();	//add some input	this.cursor = this.game.input.keyboard.createCursorKeys(); 	this.playerState = 0;	// 0 = grounded	// 1 = climbing	// 2 = hanging	// 3 = edge-hanging	// 4 = falling	// 5 = crouching	//add the dude and enable physics on him	this.player = this.game.add.sprite(400, 300, 'dude');	this.game.physics.arcade.enable(this.player);	this.player.body.collideWorldBounds = true;	this.player.body.gravity.y = 1000;	//adjust the player's anchor	this.player.anchor.setTo(0.25, 0.25);	//scale and offset the player's hitbox	this.player.body.setSize(24, 30, -6, -6)	this.player.smoothed = false;	// some info about the player animations:	// 24 fps is the standard	// 'run' is 16 frames long	this.player.animations.add('idle', [0], 0, true);	this.player.animations.add('idle_action', [0,1], 24, true);	this.player.animations.add('run', [28,29,30,31,32,33,34,35,36,37,38,39,24,25,26,27], 24, true);	this.player.animations.add('push', [40,41,42,43,44,45,46,47], 24, true);};loderunner.Game.prototype.haha = function(){	this.player.kill();};loderunner.Game.prototype.update = function(){	this.game.physics.arcade.collide(this.player, this.blockedLayer); };
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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