Uhfgood Posted September 16, 2014 Share Posted September 16, 2014 How come this doesn't work:this.game.load.image( 'explode_large', 'gfx/explosion.png' );var bmd_med = this.game.make.bitmapData( 32, 32 );bmd_med.load( 'explode_large' );it claims 'explode_large' is an invalid key Link to comment Share on other sites More sharing options...
rich Posted September 16, 2014 Share Posted September 16, 2014 I assume there is more code than this, and you're not making the bmd immediately after loading the image? Link to comment Share on other sites More sharing options...
Uhfgood Posted September 16, 2014 Author Share Posted September 16, 2014 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 More sharing options...
rich Posted September 16, 2014 Share Posted September 16, 2014 You can't create the bmd in the preload function, the files haven't yet loaded (hence the key error). Move that to the create function and it'll be fine. Link to comment Share on other sites More sharing options...
Uhfgood Posted September 16, 2014 Author Share Posted September 16, 2014 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 More sharing options...
rich Posted September 16, 2014 Share Posted September 16, 2014 Pass the bmd object itself as the texture, not the key. If you pass a string to Sprite.loadTexture it thinks you've passed an image key. Link to comment Share on other sites More sharing options...
Uhfgood Posted September 16, 2014 Author Share Posted September 16, 2014 Well I was trying to do this for constancy... but thanks, I will go ahead and do that. Link to comment Share on other sites More sharing options...
Uhfgood Posted September 16, 2014 Author Share Posted September 16, 2014 Okay so i have another problem... it works, but, the explosion is still the same size -- I thought if I made the bmd size smaller, that load would scale it down to fit -- is this not the case, do I need some other copy function? Link to comment Share on other sites More sharing options...
rich Posted September 16, 2014 Share Posted September 16, 2014 Nope, read what BitmapData.load does: http://docs.phaser.io/Phaser.BitmapData.html#load Link to comment Share on other sites More sharing options...
Uhfgood Posted September 17, 2014 Author Share Posted September 17, 2014 So the other way around, I guess I misread it (but I did read it). Okay, I'll figure this out yet. Link to comment Share on other sites More sharing options...
Recommended Posts