phaseme Posted May 17, 2018 Share Posted May 17, 2018 Hey everyone, I want to add different buttons with 2 different clickevents. If I add one button it works, if I add another one it doesn't. The Images and sounds are in my Preloader file and i tested them, so they work and aren't the problem. Any Solutions? Thank you! Game.Level0_5 = function(){}; var frido; var back; Game.Level0_5.prototype = { create:function(game){ back = this.add.sprite(game.world.centerX, game.world.centerY, 'hauptkirche'); back.scale.setTo(1.335,1); back.anchor.setTo(0.75, 0.5); frido = this.add.sprite(game.world.centerX, game.world.centerY, 'frido2'); frido.scale.setTo(0.5,0.5); frido.anchor.setTo(2.0, 0.67); this.createButton(game, " Das ist die Hauptkirche.\n \n Die Hauptkirche wurde 1085 erbaut.\n Bis zur Reformation war sie katholisch \n und wurde danach \n im Jahr 1560 evangelisch. \n Im Dreißigjährigen Krieg (1618-1648) \n wurde die Kirche zerstört \n und musste neu gebaut werden. \n \n Frage: \n Wann wurde die Hauptkirche zerstört? ", game.world.centerX +266, game.world.centerY + 155, 268, 900.0,); var button = game.add.button( game.world.centerX+265, game.world.centerY+45, 'aki', function() { this.game.sound.play('correctanswer'); this.state.start('Level1'); }, this, 0, 1, 2, 3); button.anchor.x = .5; button.anchor.y = .5; button.input.useHandCursor = true; }, var btn = game.add.button( game.world.centerX+200, game.world.centerY+60, 'bki', function() { this.game.sound.play('correctanswer'); this.state.start('Level1'); }, this, 0, 1, 2, 3); btn.anchor.x = .5; btn.anchor.y = .5; btn.input.useHandCursor = true; }, update: function(){ }, createButton:function(game, string, x, y, w, h, callback) { var button1 = game.add.button(x, y, 'button1', callback, this, 2, 1, 0); button1.anchor.setTo(0.5, 0.6); button1.width = w; button1.height = h; var txt = game.add.text(button1.x, button1.y, string, { font: 'bold 14px palatino linotype', fill: '#0000000', align:'center', wordWrap: true, wordWrapWidth: 600 }); txt.anchor.setTo(0.5, 1.5); } }; Link to comment Share on other sites More sharing options...
Recommended Posts