Phaser 3 different bounding box in atlas
Is it 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 :
"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 :
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 ?
/**
* 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;
}
phaser-framework texturepacker
add a comment |
Is it 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 :
"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 :
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 ?
/**
* 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;
}
phaser-framework texturepacker
add a comment |
Is it 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 :
"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 :
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 ?
/**
* 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;
}
phaser-framework texturepacker
Is it 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 :
"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 :
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 ?
/**
* 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;
}
phaser-framework texturepacker
phaser-framework texturepacker
edited Nov 15 '18 at 21:19
James Skemp
4,91284775
4,91284775
asked Nov 14 '18 at 8:32
Pred05Pred05
1137
1137
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295899%2fphaser-3-different-bounding-box-in-atlas%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53295899%2fphaser-3-different-bounding-box-in-atlas%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown