Todi Posted October 29, 2015 Share Posted October 29, 2015 Hello guys, So, I'm trying to scale my game to fit the screen size of my smartphone using this code: create: function () { var style = { font: "bold 32px Verdana", fill: "#f00" }; this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; this.scale.setMinMax(512, 384, 1024, 768); this.scale.pageAlignHorizontally = true; this.scale.pageAlignVertically = true; this.scale.forceOrientation(true, false); this.scale.enterIncorrectOrientation.add(this.enterIncorrectOrientation, this); this.scale.leaveIncorrectOrientation.add(this.leaveIncorrectOrientation, this); this.scale.setScreenSize(true); this.game.add.text(0, 0, 'Pizza Mayhem', style); }But it didn't work. When I debug the code it says that this.scale or this.game.scale are undefined objects. Anyone know what I'm doing wrong? Thanks! Link to comment Share on other sites More sharing options...
chongdashu Posted October 29, 2015 Share Posted October 29, 2015 I think you need this.game.world.scale Link to comment Share on other sites More sharing options...
Todi Posted October 29, 2015 Author Share Posted October 29, 2015 I think you need this.game.world.scale Doesn't work too. Link to comment Share on other sites More sharing options...
chongdashu Posted October 29, 2015 Share Posted October 29, 2015 Hmm, could you try posting it onto a jsFiddle so that we can replicate the error? It could be that your setup is wrong. You can use this as a starting point and fork it:http://jsfiddle.net/chongdashu/e80ywwhp/ Link to comment Share on other sites More sharing options...
Todi Posted October 29, 2015 Author Share Posted October 29, 2015 Hmm, could you try posting it onto a jsFiddle so that we can replicate the error? It could be that your setup is wrong. You can use this as a starting point and fork it:http://jsfiddle.net/chongdashu/e80ywwhp/ So, I'm using RequireJS, it will be really weird and not work on jsFiddle. Follow my code bellow: index.html<html> <head> <meta charset="utf-8"> <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> <title>Pizza Mayhem</title> <!-- CSS style --> <link rel="stylesheet" type="text/css" href="css/style.css"> <!-- require lib --> <script data-main="config" src="lib/require.js"></script> </head> <body> <div id="game"></div> <div id="orientation"></div> </body></html>config.js (requirejs)require.config({ baseUrl: 'js/', paths: { phaser: '../lib/phaser' }, shim: { 'phaser': { exports: 'Phaser' } }});requirejs(['Main']);Main.jsdefine(['phaser', 'Boot'], function (Phaser, Boot) { 'use strict'; var game; game = new Phaser.Game(1024, 768, Phaser.AUTO, 'game'); game.state.add('Boot', Boot); game.state.start('Boot');});Boot.jsdefine(['phaser'], function (Phaser) { 'use strict'; function Boot (game) { // code me! }; Boot.prototype.constructor = Boot; Boot.prototype.init = function () { this.scale.scaleMode = Phaser.ScaleManager.NO_SCALE; this.scale.pageAlignHorizontally = true; this.scale.pageAlignVertically = true; }; Boot.prototype.preload = function () { this.game.load.image('bg', 'assets/misc/bg.png'); }; Boot.prototype.create = function () { var style; style = { font: "bold 32px Verdana", fill: "#f00" };// this.game.add.text(0, 0, 'Pizza Mayhem', style); this.game.add.sprite(0, 0, 'bg'); }; return Boot;});Sorry for the wall of code. Thanks! EDIT: Its really weird, but, the cordova don't copy the files into the application. I don't know what happen but when I inspect my game WebView inside my Android phone, it shows this errors: http://i.imgur.com/10qRB0J.png Link to comment Share on other sites More sharing options...
chongdashu Posted October 29, 2015 Share Posted October 29, 2015 Sounds like it's not an issue on the Phaser end of things, but about the environment you've got set up. Maybe someone else with more experience with Cordova and/or RequireJS can chime in. Link to comment Share on other sites More sharing options...
Todi Posted October 29, 2015 Author Share Posted October 29, 2015 Sounds like it's not an issue on the Phaser end of things, but about the environment you've got set up. Maybe someone else with more experience with Cordova and/or RequireJS can chime in. I modified some things, following the RequireJS Template in official github of Phaser, but now the error persists on Cordova. After I modified some lines of code everything works well in browser, but not in Cordova when I try to run my application. The new error is:FAILURE: Build failed with an exception.* What went wrong:Execution failed for task ':mergeDebugAssets'.> java.lang.NullPointerException (no error message)* Try:Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.BUILD FAILEDTotal time: 4.06 secsC:\Users\Alexandre Ferreira\Projetos\HTML5\pizzamayhem\platforms\android\cordova\node_modules\q\q.js:126 throw e; ^Error code 1 for command: cmd with args: /s /c ""C:\Users\Alexandre Ferreira\Projetos\HTML5\pizzamayhem\platforms\android\gradlew" cdvBuildDebug -b "C:\Users\Alexandre Ferreira\Projetos\HTML5\pizzamayhem\platforms\android\build.gradle" -PcdvBuildArch=arm -Dorg.gradle.daemon=true"Btw, thanks for your patience! EDIT: I solved the cordova error doing remove and add the Android platform, now I will test the fullscreen mode and scale. EDIT: Everything works fine! chongdashu 1 Link to comment Share on other sites More sharing options...
Recommended Posts