Search the Community

Showing results for tags 'function'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • HTML5 Game Coding
    • News
    • Game Showcase
    • Coding and Game Design
  • Frameworks
    • Phaser
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 35 results

  1. Currently I have a group of sprites and I want to make them all fall at the same time. I am trying to accomplish this with the following functions, where the group (here: fallGroup) should fall when the down arrow key is pressed. (and yes, I have already initialized keys in the create() method) I have tried passing multiple versions of the function definition to callAll() (eg. "this.setVel", "game.setVel", ect.) as well as several different contexts instead of 'null' ("this", "that=this, then passing 'that' in", "game", "game.stage", ect.) but so far nothing happens. For some of the combos I get "TypeError: Cannot read property 'setVel' of undefined" others produce no error but also do not call my 'setVel' function. At this point I'm pretty lost as to what to do. Edit: appleYpos, groundYpos, appleTime; are all globally defined variables function setVel(sprite,vel) { sprite.body.velocity.y = vel; } function makeFall(group) { //calculate fall distance and then adjust velocity to meet time goal //note: velocity in physics.arcade is in pixels/sec let dist = appleYpos - groundYpos; let vel = dist/appleTime; group.callAll('setVel',null,vel); } function update() { if(keys.down.isDown) { makeFall(fallGroup); } }
  2. Hello Experts I need your Best Guidline I need to know Is it possible to take 3d Model Canvas Screenshot ? And How Its Work can u show me demo ?
  3. I am trying to make a gate that opens when you click on it, and rotate it 90 degrees. I have accomplished this much, but how do I make it go back to it's original position once I click on it again? For instance: *clicks on gate, gate opens, 90 degrees.* *clicks on gate again, gate closes, -90 degrees from the 90 degrees that it went on previous click* Any help would be appreciated! html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Simple Canvas Game</title> <style> html { background: black } canvas { margin: auto; } </style> </head> <body> <script src="phaser.js"></script> <script src="game.js"></script> </body> </html> game.js var game = new Phaser.Game(550, 540, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.crossOrigin = 'anonymous'; game.load.image('gateopen', 'fenceleft.png'); } var sprite function clickSprite() { console.log("clickSprite"); sprite.angle += 90; } function clickGame() { console.log("clickGame"); } function create() { sprite = game.add.sprite(100, 100, 'gateopen'); sprite.anchor = {x: 1, y: 1} game.inputEnabled = true; sprite.inputEnabled = true; game.input.onDown.add(clickGame); } function update() { } function render() { game.debug.bodyInfo(sprite, 32, 32); game.debug.body(sprite); }
  4. splitting Game.js into many files

    Hi, sorry for very noobish question I have my phaser game.js file which have reached more than 700 lines of code. I want to divide it into documents containing f.e. only create function, update, variables and other functions. I thought this will work: <div id="game"> <script type="text/javascript" src="game.js"></script> <script type="text/javascript" src="create.js"></script> <script type="text/javascript" src="update.js"></script> <script type="text/javascript" src="functions.js"></script> </div> But error, create function not found. In game.js it look like this: var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { (...) } function create() { (...) } function update() { (...) } functions....
  5. Alright. I'll cut to the chase. I'm making a simple game about abducting people, and I want the victims to run from the player or "flying saucer". This is what I have setup in the update function (I'm pretty sure the rest is irrelevant, but tell me if you need more): = game.physics.arcade.angleToXY(, -(this.player.x), -(this.player.y)); = game.physics.arcade.velocityFromAngle(, 145,;, 0, false); Now here is the error after getting to the "play" state (Oh and by the way, the game is based off of the state tutorial for phaser, except with a lot of edits and a lose.js file.): Uncaught TypeError: d.setTo is not a function at c.Physics.Arcade.velocityFromAngle (phaser.min.js:23) at Object.update (play.js:94) at c.StateManager.update (phaser.min.js:10) at c.Game.updateLogic (phaser.min.js:12) at c.Game.update (phaser.min.js:12) at c.RequestAnimationFrame.updateRAF (phaser.min.js:18) at window.requestAnimationFrame.forceSetTimeOut._onLoop (phaser.min.js:18) Please help!
  6. Function is undefined

    Hello, I'm creating, a player object with different states, e.g: onground, inair, etc I'm trying to assign a method to this.currentState. In the update loop, i'm calling this.currentState to run the assigned method (this.groundState), However, i'm receiving the following error 'this.currentState is not a function' SuperSmash.Player = function(game, x, y) {, game, x, y, 'player');; this.speed = 500; this.airSpeed = 300; this.jumpPower = 400; this.inAir = true; this.hitGround = false; this.body.gravity.y = 1350; this.currentState = this.groundState; console.log(this.currentState); // undefined }; SuperSmash.Player.prototype = Object.create(Phaser.Sprite.prototype); SuperSmash.Player.prototype.constructor = SuperSmash.Player; SuperSmash.Player.prototype.update = function() { this.currentState(); }; SuperSmash.Player.prototype.groundState = function() { console.log('ground'); } };
  7. I am having difficulty understanding this and scope in Javascript. I am attempting to create a dialogue box that pops up during various collisions, and perhaps part of the issue is I am not properly organizing my game. I can use this.showPopup("jump"); in the update function, but I cannot figure out how to call the showPopup function elsewhere, in getItem. I keep getting the error, "Uncaught TypeError: this.showPopup is not a function(…)" Any help is greatly appreciated. create: function() { ... popup = game.add.sprite(window.innerWidth/2, 200, 'box'); ... }, update:function (){ game.physics.arcade.overlap(player, cake, this.getItem); }, getItem:function(player,item) { console.log('got ' + item); item.kill(); this.showPopup("test"); }, showPopup: function(t){ popup_timer = game.time.create(false); popup_timer.add(1000, this.hidePopup, this); popup.text = t; tween = game.add.tween(popup.scale).to({x:1,y:1},500, Phaser.Easing.Elastic.Out, true); popup_timer.start(); }, hidePopup: function(){ tween = game.add.tween(popup.scale).to( { x: 0.0, y: 0.0 }, 500, Phaser.Easing.Elastic.In, true); }
  8. How can i control the initilization of the game, i know that the first that phaser do is the preload function but i want to execute some Js code and till that part is finished start the game. Help please
  9. hi, I would make a custom function to have tween more simple. I would have readable params in the function because i have a lot of value. i could do : function transition (obj,xbegin,ybegin,easing,delay,time....) //but it become difficult to read transition(player,100,100,Phaser.Easing.Linear.None,100,2000,...) but it become difficult to read. I put below a short example of what i would do : function transition(xbegin=x_begin) { console.log(x_begin) } transition(xbegin=100)//but that don't work because xbegin is undefined here the jsfiddle : Thanks.
  10. Hi, I'm new to phaser and so this might be a basic question. I did see: but that did not work for me. This code works: create: function() {, this); } backToMenu: function() { //do something } but create:function() {, {test: 0}); } backToMenu: function() { //do something with this.test } does not work at all. If you need more code, I will show you an example project. Thanks!
  11. Hello ! I really want to read the source code of phaser, but I am not that professional. the namespace Phaser is declared inside a function, so I am wondering how we can access it outside it ? (function(){ var Phaser = Phaser || {}; }).call(this); Phaser.something = 5; //Reference error, Phaser is not declared what things I ca learn to read the source code perfectly and have this awesome experience ?
  12. having trouble with a function

    Hi all, I'm having trouble with a in-built method of phaser. I want to check whether the sprite named target has been struck by the bullet or not. For this, I used the containsPoint() method of Phaser.Rectangle. My code looks like this. Am I doing something wrong? or my whole logic is wrong? Thanks in advance
  13. Hi, I'm new to pharser. I created several functions like move() in the Game.js TestGame.Game.prototype = { ... drawPath: function() { ... } Everything is working well. No I would like to access the drawPath function from outside oth the class, e.g. <button onlick="TestGame.Game.drawPath()"> but get "is not a function" Error.
  14. Global Function How?

    Hey there, I'm new to javascript and I'm trying to figure out how to create a global singleton for generic functions. I can create global variables in the Boot state, but I'd like to create an object that holds global vars and functions. I'm instancing a custom GameManager script in the index.html file like so: //initialize framework var game = new Phaser.Game(640, 960, Phaser.AUTO, 'game'); //create global object var gameManager = new GameManager(); My GameManager.js file looks like this: var GameManager = function GameManager() { console.log('game manager created'); this.myName = "adrian"; this.GetName = function() { console.log("my name is "+this.myName); } }; The problem is gameManager object is undefined elsewhere in game. Any suggestions? Thanks
  15. Greetings people smarter than myself. This is my first phaser self-guided exercise. I'm also very new to object oriented programming - and that may be the issue at hand. I have a single gamestate, "playgame", which has a placeTiles() function that I don't want to execute until a user clicks a "Begin" button. However, my code is not working as intended because the placeTiles() function is executing immediately upon loading. I think there is a fundamental concept that I'm missing. As you can see, I'm using preload, create, then some of my own - placetiles, showtile. Is it SOP for all of the functions inside playGame.prototype to run on initialization? If I don't want something running at that time, how do I prevent it or where should I move that block of code? Wouldn't it need to go within playGame somewhere? playGame.prototype = { myMoney: null, theEmpire: [], preload: function(){ game.stage.setBackgroundColor(0xEBEBFF); game.load.spritesheet("gadgets", "gadgets.png", tileSize, tileSize); }, create: function(){ // I've removed some code here where I create my background and color scheme // Create the Begin Button which should place the other tiles. var beginButton = game.add.button( 20,50,"gadgets",this.placeTiles(),this); beginButton.frame = 10; // There's a bunch more code here I've removed for this forum post */ }, placeTiles: function(){ for(var i=0; i < numCols; i++){ var serialButton = game.add.button( 250 * (i+1) , game.height/5 + (i*tileSpacing) , "gadgets" , this.showTile , this); serialButton.frame = i+1; serialButton.value = this.theEmpire[i]; }//i++ }, showTile: function(target){ //More functions, etc... },}; game.state.add("PlayGame", playGame); game.state.start("PlayGame"); };Any explanation or guidance would be most appreciated. Thank you for your time!
  16. Timer Countdown then Change State

    So typically you have a function that switch to another state that call be call via a button or sprites this.btn_gameOver =, 500, 'btn_play', this.start_gameOver, this);this.btn_gameOver.anchor.setTo(0.5,0.5);},start_gameOver: function(){'gameover', true, false, GameScore); } However when I use it within another function (updateTimer), once the countdown reached 0 and triggered, it return an error Uncaught TypeError: Cannot read property 'game' of undefined updateTimer: function(){ GameTimer--; txt_timer.text = GameTimer; if(GameTimer != 0){ console.log('it works!'); }else{ console.log('dingding'); //start_gameOver();'gameover', true, false, GameScore); } },What am I missing?
  17. Hello everyone! apologize in advance for my poor English. The thing is I've been working on a mini game of roulette machines, I have divided my game with gameStates(boot, gameStates, load, stand, play, win and lose). so some mechanics is: to start the state of play should create an image preloaded on my state of load, this will be a zodiac sign, then press the space key image should be removed and display a sprite sheet which is appended an animation. Something like this: var winState = { create: function(){ //Este estado servira de test para presion/accion de boton... var sta1 = game.add.image(300, 150, 'geminis'); sta1.scale.setTo(0.2); game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); if(game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)){ rotateAnim(); } }, rotateAnim: function(sta1){ sta1.destroy(); var sta2 = game.add.image(300, 150, 'signos'); sta2.animations.add('rotate');'rotate', 1, true); }};BUT I didn't get the expected result. The only thing I desired result is obtained with the method onInputDown (Mouse): //In Create: Function();var sta1 = game.add.sprite(170, 360, 'leo');sta1.scale.setTo(0.17);sta1.anchor.set(0.5);sta1.inputEnabled = true;, this);stopAnim: function(sta1){ //game.state.start('stand'); sta1.destroy(); var signos = game.add.sprite(170, 360, 'signos'); signos.scale.setTo(0.17); signos.anchor.set(0.5); signos.animations.add('change');'change', 5, true); }could someone tell me I'm doing wrong or that I needed to get the same result when you press a key. Thanks a lot for answers!
  18. Here is my code var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.CANVAS, 'game_area', { preload: preload, create: create, update: update}); var scaleRatio = window.devicePixelRatio / 5; var player, enemy, floor; var music; var game_state; var gravity_strength; var net_force; var style; var text, text2, text3, text4; var title_played; var level_data; var ready_to_select; function preload() { game.load.image('player', 'SpaceShipLarge.png'); game.load.image("enemy", "red.png"); game.load.image("floor", "green.jpg");"music", "firstbike.mp3"); } function create() { game.stage.backgroundColor = "#000000"; game.physics.startSystem(Phaser.Physics.ARCADE); style = { font: "65px Optima", fill: "white", align: "center"}; this.ROTATION_SPEED = 180; // degrees/second this.ACCELERATION = 200; // pixels/second/second this.MAX_SPEED = 250; // pixels/second this.DRAG = 25; // pixels/second this.GRAVITY = 90; // pixels/second/second player = game.add.sprite(game.width / 2, (game.height / 2) - 150, "player"); player.scale.setTo(scaleRatio, scaleRatio); player.anchor.setTo(0.5, 0.5); player.angle = -90; game.physics.arcade.enable(player); player.body.maxVelocity.setTo(this.MAX_SPEED, this.MAX_SPEED); player.body.drag.setTo(this.DRAG, this.DRAG); player.body.bounce.setTo(0.25, 0.25); player.body = null; player.visible = false; ready_to_select = false; floor = game.add.sprite(0, - 100, "floor"); floor.scale.setTo(scaleRatio, scaleRatio); floor.width =; floor.y = + 500; game.physics.arcade.enable(floor); floor.body.immovable = true; floor.body.allowGravity = false; game.physics.arcade.gravity.y = this.GRAVITY; music ="music"); music.loop = true; //; title_played = false; level_data = 1; game_state = "title_screen"; ready_to_select = true; //game_state = "play_state"; } function handle_input() { if(game_state == "play_state") { if(game.input.activePointer.justPressed()) { net_force = net_force - 20; } } } function generate_enemy() { } function start() { } function leftInputIsActive() { var isActive = false; isActive |= (game.input.activePointer.isDown && game.input.activePointer.x < game.width/4); return isActive; } function rightInputIsActive() { var isActive = false; isActive |= (game.input.activePointer.isDown && game.input.activePointer.x > game.width/2 + game.width/4); return isActive; } function upInputIsActive() { var isActive = false; isActive |= (game.input.activePointer.isDown && game.input.activePointer.x > game.width/4 && game.input.activePointer.x < game.width/2 + game.width/4); return isActive; } function setup_title() { //console.log(game.input.activePointer.y); if(title_played == false) { text = game.add.text(, 150, "Lift Off", style); text.anchor.set(0.5); if(level_data == 1) { text2 = game.add.text(, 380, "Play Game", style); }else { text2 = game.add.text(, 380, "Continue Game", style); } text2.anchor.set(0.5); text2.inputEnabled = true; text3 = game.add.text(, 500, "Select Level", style); text3.anchor.set(0.5); title_played = true; }, this); } function down(item) { if(level_data == 1) { text.kill(); text = game.add.text(, 150, "Level One", style); text.anchor.set(0.5); text2.kill(); text2 = game.add.text(, 380, "Gravity: 10m/s", style); text2.anchor.set(0.5); text3.kill(); } setInterval(function(){ game_state = "play_state"; text.kill();text2.kill();text3.kill(); }, 1000); } function setup_game() { if(level_data == 1 && ready_to_select == true) { game.stage.backgroundColor = "#FFFFFF"; game.physics.arcade.enable(player); player.visible = true; floor.y = - 100; enemy = game.add.sprite(game.width / 2, (game.height / 2), "player"); enemy.scale.setTo(scaleRatio, scaleRatio); enemy.anchor.setTo(0.5, 0.5); game.physics.arcade.enable(enemy); ready_to_select = false; } } function touched_floor() { player.y = 200; } function update() { game.physics.arcade.collide(player, floor); game.physics.arcade.collide(enemy, floor); game.physics.arcade.overlap(player, floor, touched_floor()); /* if (onTheGround) { if (Math.abs(player.body.velocity.y) > 20 || Math.abs(player.body.velocity.x) > 30) { // The ship hit the ground too hard. alert("gg m8"); // Blow it up and start the game over. //this.getExplosion(player.x, player.y); //this.resetShip(); } else { // We've landed! // Stop rotating and moving and aim the ship up. player.body.angularVelocity = 0; player.body.velocity.setTo(0, 0); player.angle = -90; } } */ handle_input(); if(game_state == "title_screen") { setup_title(); } if(game_state == "play_state") { setup_game(); if (player.x > game.width) player.x = 0; if (player.x < 0) player.x = game.width; if (leftInputIsActive()) { // If the LEFT key is down, rotate left player.body.angularVelocity = -this.ROTATION_SPEED; } else if (rightInputIsActive()) { // If the RIGHT key is down, rotate right player.body.angularVelocity = this.ROTATION_SPEED; } else { // Stop rotating player.body.angularVelocity = 0; } if (upInputIsActive()) { // If the UP key is down, thrust // Calculate acceleration vector based on this.angle and this.ACCELERATION player.body.acceleration.x = Math.cos(player.rotation) * this.ACCELERATION; player.body.acceleration.y = Math.sin(player.rotation) * this.ACCELERATION; // Show the frame from the spritesheet with the engine on player.frame = 1; } else { // Otherwise, stop thrusting player.body.acceleration.setTo(0, 0); // Show the frame from the spritesheet with the engine off player.frame = 0; } } } My Issue The overlap function should only be triggered when the player touches the floor. However, it is being called 60 times a second no matter where the player and the floor are in relation to each other.
  19. Function Call TypeError with

    Hey Guys, I have a problem with a function call with Phaser. I am a Javascript Noob and don´t know what I do wrong. Here is the critical Part of my Code, the whole Code is in one Scene. BasicGame.Multiplayer.prototype = {create: function(){ this.socket = io.connect('localhost:3010'); this.socket.on('startGame', function () { console.log('ShouldStartGame'); this.createActualGame(); });...},createActualGame: function(){// Define constants...}}My problem is that the function this.createActualGame is not called with the error: "TypeError: this.createActualGame is not a function". But the console log works fine. Thanks for your help! With kind regards, SirSandmann
  20. Hi, I have made a game that works fine and am trying to put some states in. I have set all the code up and I keep getting the 'Uncaught ReferenceError: MYFUNCTION is not defined'. Here is a bit of the code so you get the idea. It's the main game state. If I take out the function being called it calls the same error on the next function. I don't understand why the functions aren't being defined? var theGame = function(game){}theGame.prototype = { create: function(){ }, update: function(){ MYFUNCTION(); }, MYFUNCTION: function(player, coin) { some stuff; }}Any help would be great! Thanks
  21. Problem with functions

    Hi all, I have a little problem with functions in states, when i want to use a function from a function i get an error of undefined. To clarify here is the code: Game.Combat.prototype = { /* create and update codes ....*/ moveToEnnemy: function() { var tween =;{x:ennemy.x-32, y:ennemy.y}, 1500, Phaser.Easing.Cubic.None, true); }, moveToStart: function() { var tween =;{x:PLAYER_START_X, y:PLAYER_START_Y}, 1500, Phaser.Easing.Cubic.None, true); }, attack: function() { this.moveToEnnemy(); /*This is the probleme, i get an error of undefined function*/ console.log("ATTACKING ..."); this.moveToStart(); //This too. },}I get this error : Uncaught TypeError: undefined is not a function Is there any solution in how to use moveToEnnemy and moveToStart into the attack functions ?
  22. Hi friends, quick question: What is the path to my function? I'm not sure what to put in this field (image below). My directory looks like this: >index.html >html5contents (folder) >aqh_yepApi.js In aqh_yepiApi.js I have the functions yepiRestart(), yepiSound(), and yepiPause(). Those are the functions I'm trying to reach, but I'm not sure what to put in the field. I know what I have in the image is wrong. I use GameMaker Studio to make my games if that's relevant at all. Thanks!
  23. I'm porting a Flash/AIR project to Phaser, and everything is going pretty smoothly so far, but I hit a really odd performance issue which I'm hoping someone can explain to me. When using a forEach loop on a phaser Group (called desksGroup) which only has 9 items in it, I get ~40fps on mobile. But if I get rid of that forEach loop, and instead put the code into the built-in update() function of each of the 9 sprites within the group, FPS drops to ~4. Here is the game loop with a forEach going through a group of sprites (desksGroup): GameState.prototype.update = function() { // kill any pencils that hit a wall game.physics.arcade.overlap(layerMap, pencilsGroup, pencilHitWall); // TODO: subclass "Sprite" so that these update functions call themselves desksGroup.forEach(function(desk) { clientsGroup.forEach(function(theClient) { // get closest client if (!desk.currentTarget || desk.currentTarget && game.physics.arcade.distanceBetween(desk, theClient) < game.physics.arcade.distanceBetween(desk, desk.currentTarget)) desk.currentTarget = theClient; // other ideas for targeting: least health, most health, slowest, fastest }); if (desk.currentTarget && > 0 && game.physics.arcade.distanceBetween(desk, desk.currentTarget) < desk.range) { if ( > desk.nextFire) { desk.nextFire = + desk.fireRate; var pencil = pencilsGroup.getFirstExists(false); pencil.reset(desk.x, desk.y); pencil.lifespan = desk.fireLife; pencil.rotation = game.physics.arcade.moveToObject(pencil, desk.currentTarget, desk.fireSpeed); } } }); game.physics.arcade.overlap(clientsGroup, pencilsGroup, pencilHitClient); if(defaults.showHealth) { clientsGroup.forEach(function(client) { game.debug.geom(new Phaser.Rectangle(client.x, client.y - 16, Math.max(0, tilemap.tileWidth * ( /, 7), '#00ff00', true); }); }}And here is a slightly modified version, with that forEach removed: GameState.prototype.update = function() { // kill any pencils that hit a wall game.physics.arcade.overlap(layerMap, pencilsGroup, pencilHitWall); game.physics.arcade.overlap(clientsGroup, pencilsGroup, pencilHitClient); if(defaults.showHealth) { clientsGroup.forEach(function(client) { game.debug.geom(new Phaser.Rectangle(client.x, client.y - 16, Math.max(0, tilemap.tileWidth * ( /, 7), '#00ff00', true); }); }}With the desk update functions moved to this: var deskUpdate = function() { var desk = this; clientsGroup.forEachAlive(function(theClient) { // get closest client if (!desk.currentTarget || desk.currentTarget && game.physics.arcade.distanceBetween(desk, theClient) < game.physics.arcade.distanceBetween(desk, desk.currentTarget)) desk.currentTarget = theClient; // other ideas for targeting: least health, most health, slowest, fastest }); if (desk.currentTarget && > 0 && game.physics.arcade.distanceBetween(desk, desk.currentTarget) < desk.range) { if ( > desk.nextFire) { desk.nextFire = + desk.fireRate; var pencil = pencilsGroup.getFirstExists(false); pencil.reset(desk.x, desk.y); pencil.lifespan = desk.fireLife; pencil.rotation = game.physics.arcade.moveToObject(pencil, desk.currentTarget, desk.fireSpeed); } }}As you can see, the only difference is that I've removed the desksGroup.forEach() code block, and created an updateDesk function. Elsewhere in the code, where I instantiate the "desk" Sprites, I have the following line: desk.update = deskUpdate;I was thinking that by adding the deskUpdate function to each desk Sprite, it would save some overhead (since the .update() gets called automatically, instead of my explicitly looping through the group via forEach). However, when I use this deskUpdate function, my FPS on mobile drops from ~40fps to ~4fps. I also tried using an regular function declaration (function deskUpdate() {...}), and had the same performance loss.
  24. How to destroy a fucntion?

    I want to destroy a function, what is the best way to do that? example : FavoriteFlavor.bootState = { button: function(btnX, btnY, textX, textY, fn, text) { var button = game.add.button( + btnX, + btnY, 'btnLetGo', fn, this); button.anchor.set(0.5); button.input.useHandCursor = true; var letGo = game.add.text( + textX, + textY, text); letGo.font = 'Arial'; letGo.fill = '#ffffff'; letGo.fontSize = '13px'; letGo.align = 'center'; letGo.fontWeight = 'bold'; letGo.anchor.set(0.5); }};FavoriteFlavor.gameState.prototype = { create: function() { button = FavoriteFlavor.bootState.button(0, 130, 0, 130, this.start, "Start"); }, start: function() { //click start function destory FavoriteFlavor.bootState.button //how to do that? }};