Pred05 Posted November 14, 2018 Share Posted November 14, 2018 it is possible in Phaser 3 to define the bounding box for each sprite frame into an atlas ? When i generate an sprite sheet into TexturePacker, we can find some parameters into the .json : Quote "idle-0001.png": { "frame": {"x":1,"y":1,"w":423,"h":619}, "rotated": false, "trimmed": false, "spriteSourceSize": {"x":1,"y":1,"w": 423,"h":619, "sourceSize": {"w":423,"h":619} } and my sprite definition : Quote this.sprite = scene.physics.add.sprite(x,y,'player-idle','idle-0001.png'); this.sprite.setCollideWorldBounds(true); When i change spriteSourceSize or sourceSize, it doesn't change anything on my sprite is it normal ? it is quite strange because the method setSize change well the bounding box. In the implementation of setSize the sourceSize is update so i think it is possible to set directly a bounding box with the atlas .json ? Quote /** * Sizes and positions this Body's boundary, as a rectangle. * Modifies the Body `offset` if `center` is true (the default). * Resets the width and height to match current frame, if no width and height provided and a frame is found. * * @method Phaser.Physics.Arcade.Body#setSize * @since 3.0.0 * * @param {integer} [width] - The width of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame width. * @param {integer} [height] - The height of the Body in pixels. Cannot be zero. If not given, and the parent Game Object has a frame, it will use the frame height. * @param {boolean} [center=true] - Modify the Body's `offset`, placing the Body's center on its Game Object's center. Only works if the Game Object has the `getCenter` method. * * @return {Phaser.Physics.Arcade.Body} This Body object. */ setSize: function (width, height, center) { if (center === undefined) { center = true; } var gameObject = this.gameObject; if (!width && gameObject.frame) { width = gameObject.frame.realWidth; } if (!height && gameObject.frame) { height = gameObject.frame.realHeight; } this.sourceWidth = width; this.sourceHeight = height; this.width = this.sourceWidth * this._sx; this.height = this.sourceHeight * this._sy; this.halfWidth = Math.floor(this.width / 2); this.halfHeight = Math.floor(this.height / 2); this.updateCenter(); if (center && gameObject.getCenter) { var ox = gameObject.displayWidth / 2; var oy = gameObject.displayHeight / 2; this.offset.set(ox - this.halfWidth, oy - this.halfHeight); } this.isCircle = false; this.radius = 0; return this; } Link to comment Share on other sites More sharing options...
Recommended Posts