notalentgeek Posted October 9, 2017 Share Posted October 9, 2017 I am currently learning Phaser by doing some examples. I am currently here: https://phaser.io/examples/v2/animation/creature-dragon-multiple. I am wondering, how can I set the height and width of `Phaser.Creature` object? The default `height` and `width` are set to undefined. Hence I need to set both height and width in order to set the `Phaser.Creature` dimension. Here are some codes. dragon_character.play(true); // `true` is used for looping forever. dragon_character.scale.set(20); dragon_character.height = 100; dragon_character.width = 100; console.log(dragon_character.height); // 100. console.log(dragon_character.width); // 100. Here are another codes. dragon_character.play(true); // `true` is used for looping forever. dragon_character.scale.set(20); dragon_character.height = 100; console.log(dragon_character.height); // 100. console.log(dragon_character.width); // Undefined. // Additionally the animation does not show up in the screen. If I only set either height or width, the `Phaser.Creature` will not show up in the screen. I don't know if there is no way to set height and let the width adjusted proportionally (vice-versa). Additionally, I could not found a way to get the height and width properties if the dimension is set with `Phaser.Creature.scale.set(25)`. To sum up, my questions: Is there any way to set either height or width and let the un-set properties to adjust in proportion? How can I know the `Phaser.Creature` height and width if it is set with `Phaser.Creature.scale.set()`? Link to comment Share on other sites More sharing options...
samme Posted October 9, 2017 Share Posted October 9, 2017 This is a shortcoming of our current Creature implementation. You have to set both width and height or scale, and if you set scale, the width and height values will be incorrect. Link to comment Share on other sites More sharing options...
jjwallace Posted October 9, 2017 Share Posted October 9, 2017 get the ratio of width vs height and then multiply that Link to comment Share on other sites More sharing options...
notalentgeek Posted October 10, 2017 Author Share Posted October 10, 2017 12 hours ago, jjwallace said: get the ratio of width vs height and then multiply that I found a weird behavior.... dragon_character.play(true); // `true` is used for looping forever. dragon_character.scale.set(1); console.log("=========="); console.log("after setting up scale and before setting up width and height"); console.log("scale.x = " + dragon_character.scale.x); // `1`, which is expected. console.log("scale.y = " + dragon_character.scale.y); // `1`, which is expected. console.log("height = " + dragon_character.height); // `undefined`, which is expected. console.log("width = " + dragon_character.width); // `undefined`, which is expected. console.log("=========="); dragon_character.height = dragon_character.scale.y*100; dragon_character.width = dragon_character.scale.x*100; console.log("=========="); console.log("after setting up scale and after setting up width and height"); console.log("scale.x = " + dragon_character.scale.x); // `0`, which is NOT expected. console.log("scale.y = " + dragon_character.scale.y); // `4.138100158128295`, which is NOT expected. console.log("height = " + dragon_character.height); // `100`, which is expected. console.log("width = " + dragon_character.width); // `0`, which is expected, if the `scale.x` is indeed `0`. console.log("=========="); dragon_characters.push_with_limit(dragon_character); Here is my full codes: https://pastebin.com/fk5ZZ5e8. Link to comment Share on other sites More sharing options...
Guy Konan Posted October 26, 2018 Share Posted October 26, 2018 Hi, Currently also learning Phaser by doing some examples. Out of curiosity, how is the dragon.json generated? Link to comment Share on other sites More sharing options...
samme Posted October 26, 2018 Share Posted October 26, 2018 https://creature.kestrelmoon.com Link to comment Share on other sites More sharing options...
Recommended Posts