Ivasik Posted March 23, 2016 Share Posted March 23, 2016 Hi, i have a custom buttons and i want apply anchor. How to do it? Custom buttons: this.button_start = this.btn("Play a game", this.play_game, 2.03, 15.1, 2, 8.5, 140, 30); btn: function(name, functions, anc1X, anc1Y, anc2X, anc2Y, w, h) { this.button = this.game.add.button(this.game.width, this.game.height, '', functions, this); this.button.name = name; this.button.width = w; this.button.height = h; this.button.anchor.set(anc1X, anc1Y);//Temporary this.text = this.add.bitmapText(this.game.width, this.game.height, 'Text_mainmenu', this.button.name, 46); this.text.anchor.set(anc2X, anc2Y);//Temporary } /* name - the name of the button functions - button function anc1X - first anchor.setX anc1Y - first anchor.setY anc2X - two anchor.setX anc2Y - two anchor.setY */ Link to comment Share on other sites More sharing options...
Ivasik Posted March 23, 2016 Author Share Posted March 23, 2016 @rich help me!:) Link to comment Share on other sites More sharing options...
cardex107 Posted March 23, 2016 Share Posted March 23, 2016 Hello, the correct code is: anchor.setTo(dataX, dataY); But you in the add function have the position at: (this.game.width, this.game.height) the total position not show button, is out of screen, its better use (this.game.world.centerX, this.game.world.centerY). Link to comment Share on other sites More sharing options...
Ivasik Posted March 23, 2016 Author Share Posted March 23, 2016 2 hours ago, cardex107 said: Hello, the correct code is: anchor.setTo(dataX, dataY); But you in the add function have the position at: (this.game.width, this.game.height) the total position not show button, is out of screen, its better use (this.game.world.centerX, this.game.world.centerY). this.game.width, this.game.height you need to resize the elements do not remain in place and has changed his position. //example this.play_game= this.add.button(this.game.width, this.game.height, 'test_button', this.play_game_functions, this); this.play_game.anchor.set(1.65, 7.5); resize: function(width, height) { this.play_game.x = this.game.width; this.play_game.y = this.game.height; } Link to comment Share on other sites More sharing options...
cardex107 Posted March 23, 2016 Share Posted March 23, 2016 2 minutes ago, Ivasik said: this.game.width, this.game.height you need to resize the elements do not remain in place and has changed his position. //example this.play_game= this.add.button(this.game.width, this.game.height, 'test_button', this.play_game_functions, this); this.play_game.anchor.set(1.65, 7.5); resize: function(width, height) { this.play_game.x = this.game.width; this.play_game.y = this.game.height; } ok, only need anchor.setTo Link to comment Share on other sites More sharing options...
Ivasik Posted March 23, 2016 Author Share Posted March 23, 2016 5 minutes ago, cardex107 said: ok, only need anchor.setTo For to set custom button or for button and text? Link to comment Share on other sites More sharing options...
Ivasik Posted March 23, 2016 Author Share Posted March 23, 2016 If a custom button that displays an error: Uncaught TypeError: Cannot read property 'anchor' of undefined If the text and buttons all in the same way as with anchor.set. :\ Link to comment Share on other sites More sharing options...
Recommended Posts