Skip to content

Commit 21a6390

Browse files
committed
Implemented auto-size for Phaser blocks.
Use the value 0 to use the auto-size feature for Phaser blocks. Adjusted the preview to represent the correct height and width.
1 parent bbfd910 commit 21a6390

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

src/blocks/phaser/game/javascript.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ Blockly.JavaScript['phaser_game'] = function(block) {
2929
let number_width = block.getFieldValue('width');
3030
let number_height = block.getFieldValue('height');
3131
return 'var obstacle_group;\n' +
32-
'var game = new Phaser.Game(' + number_width + ', ' + number_height +
33-
', Phaser.AUTO, \'' + text_name + '\');\n';
32+
'var game = new Phaser.Game(' + number_width + ' || window.innerWidth, ' +
33+
number_height + ' || window.innerHeight, Phaser.AUTO, \'' +
34+
text_name + '\');\n';
3435
};
3536

3637

src/ui/preview/preview.gss

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
#{$prefix}preview-content iframe,
5656
#{$prefix}preview-content webview {
5757
flex: 1 1 auto;
58-
min-height: 100vh;
59-
min-width: 100vw;
58+
min-height: calc(100vh - 26px - 34px);
6059
}
6160

6261
#{$prefix}preview-infobar {

static_files/resources/examples/phaser/blocks/bouncing-cubes.cwc

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

static_files/resources/examples/phaser/blocks/move-a-sprite.cwc

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

static_files/resources/examples/phaser/blocks/switch-game-state.cwc

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

static_files/resources/templates/phaser/blank-blocks.cwc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"name": "blockly",
66
"type": "application/blockly+xml",
77
"size": 1004,
8-
"content": "<xml xmlns=\"http://www.w3.org/1999/xhtml\">\n <block type=\"phaser_game\" x=\"-250\" y=\"-250\">\n <field name=\"name\">Unnamed Game</field>\n <field name=\"width\">400</field>\n <field name=\"height\">600</field>\n <next>\n <block type=\"phaser_game_state\">\n <field name=\"name\">main</field>\n <field name=\"autostart\">true</field>\n <statement name=\"state\">\n <block type=\"phaser_preload\">\n <next>\n <block type=\"phaser_create\">\n <next>\n <block type=\"phaser_input\">\n <next>\n <block type=\"phaser_update\">\n <next>\n <block type=\"phaser_render\" collapsed=\"true\"></block>\n </next>\n </block>\n </next>\n </block>\n </next>\n </block>\n </next>\n </block>\n </statement>\n </block>\n </next>\n </block>\n</xml>",
8+
"content": "<xml xmlns=\"http://www.w3.org/1999/xhtml\">\n <block type=\"phaser_game\" x=\"-250\" y=\"-250\">\n <field name=\"name\">Unnamed Game</field>\n <field name=\"width\">0</field>\n <field name=\"height\">0</field>\n <next>\n <block type=\"phaser_game_state\">\n <field name=\"name\">main</field>\n <field name=\"autostart\">true</field>\n <statement name=\"state\">\n <block type=\"phaser_preload\">\n <next>\n <block type=\"phaser_create\">\n <next>\n <block type=\"phaser_input\">\n <next>\n <block type=\"phaser_update\">\n <next>\n <block type=\"phaser_render\" collapsed=\"true\"></block>\n </next>\n </block>\n </next>\n </block>\n </next>\n </block>\n </next>\n </block>\n </statement>\n </block>\n </next>\n </block>\n</xml>",
99
"version": 1
1010
},
1111
"__javascript__": {
1212
"name": "__javascript__",
1313
"type": "application/javascript",
1414
"size": 429,
15-
"content": "var obstacle_group;\nvar game = new Phaser.Game(400, 600, Phaser.AUTO, 'Unnamed Game');\ngame.state.add('main', {\n preload: function(e) {\n },\n create: function () {\n if (navigator.userAgent == 'CwC sandbox') {game.time.desiredFps = 30;}\n obstacle_group = game.add.group(undefined, 'obstacle_group');\n },\n input_: function(e) {\n },\n update: function(e) {\n this.input_(e);\n },\n render: function(e) {\n },\n}, true);\n",
15+
"content": "",
1616
"version": 1
1717
}
1818
},

0 commit comments

Comments
 (0)