Jump to content

"invalid key" -- this code isn't working.


Uhfgood
 Share

Recommended Posts

I'm using this example as my basis - http://examples.phaser.io/_site/view_full.html?d=bitmapdata&f=set+hsl.js&t=set%20hsl

 

This code is in my preloader:

Sroids.Preloader = function( game ) {	Sroids.GAME_WIDTH = 800;	Sroids.GAME_HEIGHT = 600;};Sroids.Preloader.prototype ={	preload: function()	{		this.preloadBar = this.add.sprite( ( Sroids.GAME_WIDTH - 720 ) / 2, ( Sroids.GAME_HEIGHT-32 ) / 2, 'preloaderBar' );		this.load.setPreloadSprite( this.preloadBar );				this.game.load.image( 'splash', 'gfx/splash_square.png' );		this.game.load.spritesheet( 'explosion', 'gfx/explode.png', 64, 64 );		this.game.load.spritesheet('ship', 'gfx/ship.png', 32, 32);		this.game.load.image('bullet', 'gfx/bullet.png');		// load asteroid graphics		this.game.load.spritesheet( 'ast_yellow', 'gfx/ast_yellow.png', 64, 64 );		this.game.load.spritesheet( 'ast_red', 'gfx/ast_red.png', 64, 64 );		this.game.load.spritesheet( 'ast_green', 'gfx/ast_green.png', 64, 64 );		this.game.load.spritesheet( 'ast_blue', 'gfx/ast_blue.png', 64, 64 );		this.game.load.spritesheet( 'ast_gray', 'gfx/ast_gray.png', 64, 64 );		this.game.load.image( 'explode_large', 'gfx/explosion.png' );				var bmd_med = this.game.make.bitmapData( 32, 32 );		bmd_med.load( 'explode_large' );//		bmd_med.key = 'explode_medium';	},		create: function()	{		this.state.start( 'Game' );	}};
Link to comment
Share on other sites

Thanks, I just did that, now I'm trying to do something else -- I want to use the bmd image as a texture -- and what I did was try to set the bmd.key to what I wanted to use -- is there a way I can do this?

 

here's the updated preloader;

Sroids.Preloader = function( game ) {	Sroids.GAME_WIDTH = 800;	Sroids.GAME_HEIGHT = 600;};Sroids.Preloader.prototype ={	preload: function()	{		this.preloadBar = this.add.sprite( ( Sroids.GAME_WIDTH - 720 ) / 2, ( Sroids.GAME_HEIGHT-32 ) / 2, 'preloaderBar' );		this.load.setPreloadSprite( this.preloadBar );				this.game.load.image( 'splash', 'gfx/splash_square.png' );		this.game.load.spritesheet( 'explosion', 'gfx/explode.png', 64, 64 );		this.game.load.spritesheet('ship', 'gfx/ship.png', 32, 32);		this.game.load.image('bullet', 'gfx/bullet.png');		// load asteroid graphics		this.game.load.spritesheet( 'ast_yellow', 'gfx/ast_yellow.png', 64, 64 );		this.game.load.spritesheet( 'ast_red', 'gfx/ast_red.png', 64, 64 );		this.game.load.spritesheet( 'ast_green', 'gfx/ast_green.png', 64, 64 );		this.game.load.spritesheet( 'ast_blue', 'gfx/ast_blue.png', 64, 64 );		this.game.load.spritesheet( 'ast_gray', 'gfx/ast_gray.png', 64, 64 );		this.game.load.image( 'explode_large', 'gfx/explosion.png' );			},		create: function()	{		var bmd_med = this.game.make.bitmapData( 32, 32 );		bmd_med.load( 'explode_large' );		bmd_med.key = 'explode_medium';				var bmd_sml = this.game.make.bitmapData( 16, 16 );		bmd_sml.load( 'explode_large' );		bmd_sml.key = 'explode_small';		this.state.start( 'Game' );	}};

Basically I want to call load texture whenever I want the medium and small images with a string -- is this possible?

 

Here's where I tried to use it:

	// explode just sets up an explosion graphic	explode: function( lifespan )	{		for( var i = 0; i < this.NUM_CLONES; i++ )		{			var explosion = this.explosions[ i ];			if( explosion != null )			{				explosion.x = this.clones[ i ].x;				explosion.y = this.clones[ i ].y;				if( this.size === 'large' )					explosion.loadTexture( 'explode_large' );				else if( this.size === 'medium' )					explosion.loadTexture( 'explode_medium' );				else if( this.size === 'small' )					explosion.loadTexture( 'explode_small' );				explosion.lifespan = lifespan;				explosion.revive();			}		}	},
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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