Recently, there was a small game with horizontal screen development needs, and then I chose to develop it with pahser 2.6.2. I found that after rotating the game world 90 degrees, the whole game world would shake violently when the camera followed the sprite
function resize() {
let canvas = document.querySelector('canvas')
canvas.style.height = window.innerWidth + 'px'
canvas.style.width = window.innerHeight + 'px'
}
function launch(containerId, vm) {
console.log(vm)
let width = window.innerWidth
let height = window.innerHeight
// let width = 300
// let height = 600
var game = new window.Phaser.Game( width,height,window.Phaser.CANVAS,containerId)
console.log(window.Phaser)
// 第一场景,预先加载加载页所需要的背景图
let bootState = function (game){
let direction = '1'
this.preload = function() {
game.load.image('backg',${url}bg1.png)
This GitHub is for Phaser 3. If you need help with Phaser CE please report the issue, as long as it's an actual issue with the API and not your code, to the Phaser CE repo.
Recently, there was a small game with horizontal screen development needs, and then I chose to develop it with pahser 2.6.2. I found that after rotating the game world 90 degrees, the whole game world would shake violently when the camera followed the sprite
demo:
window.PIXI = require('phaser2/build/custom/pixi.min') window.p2 = require('phaser2/build/custom/p2.min') window.Phaser = require('phaser2/build/custom/phaser-split.min')
// window.Phaser = require('phaser')
let url = './game/ball/'
function resize() { let canvas = document.querySelector('canvas') canvas.style.height = window.innerWidth + 'px' canvas.style.width = window.innerHeight + 'px' }
function launch(containerId, vm) { console.log(vm) let width = window.innerWidth let height = window.innerHeight // let width = 300 // let height = 600
var game = new window.Phaser.Game( width,height,window.Phaser.CANVAS,containerId) console.log(window.Phaser) // 第一场景,预先加载加载页所需要的背景图 let bootState = function (game){ let direction = '1' this.preload = function() { game.load.image('backg',
${url}bg1.png
)//Rotate 90 degrees window.Phaser.World.prototype.displayObjectUpdateTransform = function () { if (direction == '1') { game.scale.setGameSize(height, width) this.x = game.camera.y + game.width this.y = -game.camera.x this.rotation = window.Phaser.Math.degToRad(window.Phaser.Math.wrapAngle(90)) } window.PIXI.DisplayObject.prototype.updateTransform.call(this) } } this.create = function () { game.state.start('loader') } } // scene two let loaderState = function (game){ var progressText this.init = function() { game.add.image(0, 0, 'backg') progressText = game.add.text(game.world.centerX - 50, game.world.centerY + 70, '0%', { fill: '#fff', fontSize: '16px' }) progressText.font = '微软雅黑' } this.preload = function() { game.load.atlasXML('btn',
${url}btn/btn.png
,${url}btn/sprite.xml
) game.load.image('background',${url}ceshi.jpg
) game.load.image('player',${url}player/player.png
)}
let testBtn = function(game){ var btnss this.create = function () { game.add.image(0,0, 'backg') btnss = game.add.button(game.world.centerX, game.world.centerY,'btn', function () { // game.state.start('runState') console.log(123) game.state.start('start') }, game, 0, 0, 3, 0) btnss.animations.add('bleft',[1]) btnss.play(10, true) btnss.scale.set(0.4) } }
let startGame = function (game){ var player var cursors
} game.state.add('boot', bootState) game.state.add('loader', loaderState) game.state.add('test', testBtn) game.state.add('start', startGame) game.state.start('boot')//Opening scenario 1 window.focus() return game
}
export default launch export { launch, resize }