sergil Posted November 12, 2013 Share Posted November 12, 2013 When in the preload I use the code:this.load.image('tank_GREEN' , 'assets/sprites/tank-green.png', 120, 120 ); when I create a extended sprite that automatically moves vertical using a sinusoidal waveusing:this.posX = game.rnd.integerInRange(60 + this.maxwaveSize, game.width - 60 - this.maxwaveSize);this.posY = game.height + 50;Phaser.Sprite.call(this, game, this.posX, this.posY, 'tank_GREEN');this.anchor.setTo(0.5, 0.5); how can I know the size of the preloaded image to automate the 60 in this.posX?? Now, I'm making a game prototype and not knowing the size of the sprite, makes me manually change the code if latter I change the final sprite size Thanks Link to comment Share on other sites More sharing options...
rich Posted November 12, 2013 Share Posted November 12, 2013 game.cache.getImage(key) and then it will have width/height properties on the returned object. This will be of the entire image, so if you plan on wrapping your sprites into a texture atlas when you're done you may want to rethink how you do this Matt 1 Link to comment Share on other sites More sharing options...
sergil Posted November 12, 2013 Author Share Posted November 12, 2013 ok actually I'm working with multiple images but in final development I was thinking on moving all of this to a texture atlas... using a texture atlas, I think that the json contains the x,y width and height of every image? How do you have a single sprite texture height and with from a texture atlas? Thanks Link to comment Share on other sites More sharing options...
rich Posted November 12, 2013 Share Posted November 12, 2013 Yes an atlas contains all the data you need (sourceSprite values) which you can get from the frame property. Link to comment Share on other sites More sharing options...
sergil Posted November 12, 2013 Author Share Posted November 12, 2013 thanks Link to comment Share on other sites More sharing options...
MaraRoses Posted November 15, 2017 Share Posted November 15, 2017 Hello Well i have a texture atlas with some sprite. I add in stage the sprite like this: this.testImage = new Phaser.Sprite(this.game, 0, 0, 'atlas', 'test'); this.gameContainerGroup.add(this.testImage); Now need in my code to use the texture of this sprite. When i write this.testImage.texture shows me the whole atlas. Please need a help anyone can help what can i do? Link to comment Share on other sites More sharing options...
samme Posted November 15, 2017 Share Posted November 15, 2017 @MaraRoses make sure you used load.atlas(). examples/v2/loader/load-texture-atlas Link to comment Share on other sites More sharing options...
Recommended Posts