Twiggy Posted March 27, 2019 Share Posted March 27, 2019 game.module( 'game.main' ) .body(function() { game.addAsset('square.png'); game.createScene('Main', { backgroundColor: 'blue', init: function() { //add Physics this.world = new game.Physics(); this.world.gravity.y = 2000; //boundary physics body(floor) var floor = new game.Body(); var shape = new game.Rectangle(); //shape of physics body shape.width = game.width; shape.height = 60; //position for floor physics body floor.position.x = game.width / 2; floor.position.y = game.height - 30; //collision floor.collisionGroup = 1; floor.static = true; //add created shape to body floor.addShape(shape); //add body to world floor.addTo(this.world); //roof / top collision var roof = new game.Body(); roof.position.x = game.width / 2; roof.position.y = 30; roof.collisionGroup = 1; roof.static = true; roof.addShape(shape); roof.addTo(this.world); //Left / Right Border collision var borderL = new game.Body(); var borderShape = new game.Rectangle(); borderShape.width = 60; borderShape.height = 900; borderL.position.x = 30; borderL.position.y = game.height / 2; borderL.collisionGroup = 2; borderL.static = true; borderL.addShape(borderShape); borderL.addTo(this.world); var borderR = new game.Body(); borderR.position.x = game.width - 30; borderR.position.y = game.height / 2; borderR.collisionGroup = 2; borderR.static = true; borderR.addShape(borderShape); borderR.addTo(this.world); //containers this.obstacleLayer = new game.Container(); this.playerLayer = new game.Container(); this.collectableLayer = new game.Container(); //add containers to the stage this.obstacleLayer.addTo(this.stage); this.playerLayer.addTo(this.stage); this.collectableLayer.addTo(this.stage); this.player = new game.Player(); this.player.sprite.addTo(this.world); } }); game.createClass('Player', { init: function() { this.sprite = new game.Sprite('square.png'); this.sprite.anchorCenter(); this.body = new game.Body(); this.body.position.x = game.width / 2; this.body.position.y = game.height - 100; //possible collision groups this.body.collideAgainst = [1,2]; this.body.velocityLimit.y = 1150; var shape = new game.Rectangle(); shape.width = this.sprite.width; shape.height = this.sprite.height; this.body.addShape(shape); this.body.addTo(game.scene.world); this.body.collide = this.collide.bind(this); } }); }); Hey Guys, work finally slowed down enough to give me time to give Panda2 another shot but I need some help. I receive this error, but am not sure what it means when I edit the Player class "this.body.collide = this .collide.bind(this); Uncaught TypeError: Cannot read property 'indexOf' of undefined when I try to comment that section out it gives me Uncaught TypeError: Cannot read property 'indexOf' of undefined what am I missing? Also if I made an error in how I posted let me know so I dont in the future. Quote Link to comment Share on other sites More sharing options...
enpu Posted March 27, 2019 Share Posted March 27, 2019 Hi @Twiggy I did take a quick look at your code and spotted one issue. this.body.collide = this.collide.bind(this); You are binding your body collide function to new collide function in your Player class, but you have not created that function. You should create it, like this: game.createClass('Player', { init: function() { this.sprite = new game.Sprite('square.png'); this.sprite.anchorCenter(); this.body = new game.Body(); this.body.position.x = game.width / 2; this.body.position.y = game.height - 100; //possible collision groups this.body.collideAgainst = [1,2]; this.body.velocityLimit.y = 1150; var shape = new game.Rectangle(); shape.width = this.sprite.width; shape.height = this.sprite.height; this.body.addShape(shape); this.body.addTo(game.scene.world); this.body.collide = this.collide.bind(this); }, collide: function(body) { // Body collides with another body } }); Quote Link to comment Share on other sites More sharing options...
Twiggy Posted March 28, 2019 Author Share Posted March 28, 2019 Hello @enpu, I still received the :Uncaught TypeError: Cannot read property "indexOf" of undefined. Im going to try rewriting that class entry altogether. Thank you for the speedy reply Quote Link to comment Share on other sites More sharing options...
enpu Posted March 28, 2019 Share Posted March 28, 2019 Can you tell the filename and line number of the error too. That would help a lot. You should see that in the JavaScript console. Thanks! Quote Link to comment Share on other sites More sharing options...
Twiggy Posted March 28, 2019 Author Share Posted March 28, 2019 It didnt give me a line on m in the editor but if it pops up again I should check the console? Quote Link to comment Share on other sites More sharing options...
enpu Posted March 28, 2019 Share Posted March 28, 2019 It should give you the file and line number in the end of the error message, like this: Open dev tools and console to see more info about the error, like this: Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.