Jfault Posted December 30, 2015 Share Posted December 30, 2015 Hi everyone!I'm using Phaser for a school projects, and our team needs a lot of rectangles of varying sizes and colors, but they need to have collision. I've tried creating a Graphics object and adding it as a child of a sprite. The sprite.addChild function works without a hitch. However, whenever I try to enable physics on the sprite, I get an error: (all the objects render, (the player, the rectangle, etc) but nothing moves) Here is the code in question:walls = this.add.graphics(0,0);walls.boundsPadding = 0;walls.beginFill(0xFFCCAA, 1);walls.drawRect(0,game.world.height-30,game.world.width,30);con = this.add.sprite(0,0,null);con.addChild(walls);game.physics.enable(con, Phaser.Physics.ARCADE);con.body.immovable = true;If I comment the last two lines out, the player moves as expected, though it does not collide with the platform.What's up, and how can I fix this?Thanks. Link to comment Share on other sites More sharing options...
Get_Bentley Posted December 31, 2015 Share Posted December 31, 2015 Well I am not sure exactly how to help you since it is showing an error on a piece of code that you didnt post.... but if you comment out those last two lines and the code works there could be an error there as well. Try changing game.physics.enable(con, Phaser.Physics.ARCADE);to game.physics.arcade.enableBody(con); as for collisions you need to update method // in update game.physics.arcade.collide(con, whatever other sprite you want it to collide with); let me know if this helped. Link to comment Share on other sites More sharing options...
Jfault Posted December 31, 2015 Author Share Posted December 31, 2015 I did what you told me to. Now the game runs, but the graphics object still doesn't have collision. Link to comment Share on other sites More sharing options...
Get_Bentley Posted December 31, 2015 Share Posted December 31, 2015 Did you add the collision in the update method? Link to comment Share on other sites More sharing options...
Jfault Posted December 31, 2015 Author Share Posted December 31, 2015 Nevermind, I found a much better way to do this. I think ARCADE physics don't work with graphics.I did have the collision in update.My really sketchy solution was to create a 1x1 white png called "tile" and scale it to achieve desired dimensions. Link to comment Share on other sites More sharing options...
Recommended Posts