phaser2.6版本的tileSprite如何让图片宽度自适应?
我想实现背景无限滚动的效果,用tileSprite可以做,但是图片是放大过的,宽度明显大于屏幕宽度。下面是我的关键代码:
var width = document.documentElement.clientWidth
var height = document.documentElement.clientHeight
var game = new Phaser.Game(width, height, Phaser.AUTO, "game")
var gamebg
var states = {
preload: function(){
this.preload = function(){
game.stage.backgroundColor = '#f0f';
// 加载游戏资源
game.load.crossOrigin = 'anonymous'; // 设置跨域
game.load.image('gamebg', './images/gamebg.png');
game.load.onLoadComplete.add(function(){
game.state.start("created")
});
}
},
created: function(){
this.create = function(){
gamebg = game.add.tileSprite(0, 0, width, height,'gamebg');
console.log(width,height)
},
this.update = function(){
gamebg.tilePosition.y += 2
}
}
}
// 添加场景到游戏示例中
Object.keys(states).map(function (key) {
game.state.add(key, states[key]);
});
// 启动游戏
game.state.start('preload');