levshkatov Posted October 20, 2015 Share Posted October 20, 2015 How to include physics? I tried that: game.physics.enable(bg, Phaser.Physics.ARCADE);Where bg is game.add.sprite But I have an error: game.physics.enable is not a function What is wrong? Link to comment Share on other sites More sharing options...
rich Posted October 20, 2015 Share Posted October 20, 2015 The code is fine, so it has to be something else we can't see outside of what you've put in your post. Link to comment Share on other sites More sharing options...
levshkatov Posted October 20, 2015 Author Share Posted October 20, 2015 var socket = io();window.onload = function() { var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render }); function preload () { game.load.image('bg', '/img/bg.png'); game.load.image('ship', '/img/ship.png'); } var ship; var bg; var coords = {x:0, y:0};; function create () { game.world.setBounds(0, 0, 2500, 1600); bg = game.add.sprite(-(1250 - window.innerWidth/2), -(800 - window.innerHeight/2), 'bg'); ship = game.add.sprite(window.innerWidth/2, window.innerHeight/2, 'ship') coords.x = game.input.mousePointer.x; coords.y = game.input.mousePointer.y; game.camera.follow(bg); game.physics.enable(bg, Phaser.Physics.ARCADE); } function update() { //game.camera.x = ((window.innerWidth/2 - coords.x)/window.innerWidth)*1.5; //game.camera.y = ((window.innerHeight/2 - coords.y)/window.innerHeight)*1.5; game.physics.arcade.moveToPointer(bg, 100); } function render() { }};Ok, here is whole code. Link to comment Share on other sites More sharing options...
chongdashu Posted October 21, 2015 Share Posted October 21, 2015 Looks fine to me: https://jsfiddle.net/chongdashu/ex1zy5yh/ I don't see the error you are getting. Link to comment Share on other sites More sharing options...
Recommended Posts