Raxxen

Members
  • Content Count

    7
  • Joined

  • Last visited

  1. Hey all, I ended up getting it to work! Thanks so much for your help.
  2. Hey, Xerver, When I tried your first method i got the error that the button has no method "on". EDIT: When I tried the second method, I am unsure of how to get the button's colour. Board.prototype.onClick = function(e) { this.nextColor(e.color); //Doesn't work, also tried calling this.color but to no avail};Cheers
  3. Thank Qqwy! That worked perfectly. Xerver you said that a closure repeated created should be avoided. Are you referring to the way I call a loop to make my buttons? If so what's an alternative method? Thanks for your help!
  4. Hmm... I tried that and it didn't help. I don't know if it will help but you can look at the actual game here: http://www.theboomstickstudios.com/games/OCF.
  5. Hi all, I am currently trying to use buttons in a game. I followed a tutorial on how to make them and they work well. The only problem is I am getting a problem with scope. I have created a board object then set alot of values using this.values. However when I made my buttons they also used this.values. I am having trouble trying to get it sorted out. Here is my code. Hopefully you can understand this better then my explanation: Board.prototype.setup = function() { //Create all the buttons. var buttonTexture = PIXI.Texture.fromImage("./button.png"); // this just makes a button and a button array. var buttons = []; for (var i = 0; i < this._tokenColors.length; i++) { var button = new PIXI.Sprite(buttonTexture); button.anchor.x = 0.0; button.anchor.y = 0.0; button.buttonMode = true; button.interactive = true; button.position.x = (viewWidth/6) * (i % 6); button.position.y = viewHeight - 100; button.color = this._tokenColors[i]; button.tint = button.color; stage.addChild(button); buttons.push(button); //I tried getting it to use a function in the Board class. button.mousedown = button.touchstart = function(data) { Board.prototype.nextColor(this.color); }; }};//Here is the function it calls when pressedBoard.prototype.nextColor = function (color) { document.getElementById("debug").innerHTML = color + " has been pressed"; this._nextColor = color; //This should set the BOARD'S next color this._ready = true; //This should set the BOARD to ready}I believe what is happening is instead of passing the values to the Board class, it is passing it to the button that calls the function instead. I just have no idea how to fix this. Any help would be greatly appreciated! Lenny
  6. Ahh.. Thank you so much! That fixed it straight away! Cheers!
  7. Hi all, I'm currently trying to learn coding and Javascript using Pixi to make a clone of Colour Flood. I am having trouble extending the Graphics class (sorry I am unsure if class is the right word) in Pixi. I have two JS files, one called game.js for the game and one called token.js for the token class. What happens is when I run the program on my web server, I get an error that says "Cannot read property 'points' of undefined." This occurs right as I try use the drawRect function. Here's the code for my token function Token (color) { this._R = Math.floor(color/0x10000); this._G = Math.floor(color/0x100-this._R*0x100); this._B = color - this._R*0x10000 - this._G*0x100;}Token.prototype = Object.create(PIXI.Graphics.prototype);Token.prototype.constructor = Token;//Find a smooth transition to the next colourToken.prototype.findTransition = function(color, steps) { this._nextR = Math.floor(color/0x10000); this._nextG = Math.floor(color/0x100-this._nextR*0x100); this._nextB = color - this._nextR*0x10000 - this._nextG*0x100; this._tranR = (this._R - this._nextR)/steps; this._tranG = (this._G - this._nextG)/steps; this._tranB = (this._B - this._nextB)/steps;};I haven't really done much with it yet. Here's the code for my game: var viewWidth = 640;var viewHeight = 420;//Make a pixi Renderervar renderer = PIXI.autoDetectRenderer(viewWidth, viewHeight);renderer.view.className = "rendererView";// add render view to DOMdocument.body.appendChild(renderer.view);//create a new instance of pxi stagevar stage = new PIXI.Stage(0x000000);//Create an Array for the Squarevar squareArray = [];var totalSquare = 100;var colors = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00];for (var i = 0; i < totalSquare; i++) { var color = colors[Math.floor(Math.random()*4)]; var Token = new Token(color); Token.beginFill(color); var layer = Math.floor(i/10); Token.posX = viewWidth/11*((i+1)-(layer*10)); Token.posY = viewHeight/11*(layer+1); Token.drawRect(Token.posX, Token.posY, 10, 10); stage.addChild(Token); squareArray.push(Token);}renderer.render(stage);If you need any more info let me know. Thanks for the help! Lenny