Jump to content

Using a Multidimensional array to Display sprites and Movements


Recommended Posts

I am trying to create a simple Multidimensional array that will add a sprite to the spot example [0,0]

I was following how this http://www.joshmorony.com/how-to-create-a-candy-crush-or-bejeweled-game-in-phaser/

was doing by doing something similar like:

this.tileGrid = [
    [null, null, null, null, null, null],
    [null, null, null, null, null, null],
    [null, null, null, null, null, null],
    [null, null, null, null, null, null],
    [null, null, null, null, null, null],
    [null, null, null, null, null, null]

but all I want is being change those  position in the grid to sprite and none of the animation just simply to be there.

 addTileItem: function(x, y){

    //Choose a random tile to add
    var tileToAdd = this.tileTypes[1];  

    //Add the tile at the correct x position, but add it to the top of the game (so we can slide it in)
    var tile = this.tiles.create((x * this.tileWidth) + this.tileWidth / 2, 0, tileToAdd);

    //Animate the tile into the correct vertical position
    this.game.add.tween(tile).to({y:y*this.tileHeight+(this.tileHeight/2)}, 500, Phaser.Easing.Linear.In, true)

    //Set the tiles anchor point to the center
    tile.anchor.setTo(0.5, 0.5);

    //Enable input on the tile
    tile.inputEnabled = true;

    //Keep track of the type of tile that was added
    tile.tileType = tileToAdd;

    //Trigger the tileDown function whenever the user clicks or taps on this tile
    tile.events.onInputDown.add(this.tileDown, this);

    return tile;


I think I am overthinking the problem but I been at this for a while any help would be greatly appreciated.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...