Jump to content

Tell me I'm an idiot


Recommended Posts

var game = new Phaser.Game(320, 480, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });function preload() {}function create() {    var squares = [];    for (var i = 0; i < 20; i++) {        var square = game.add.graphics(0, 0);        square.beginFill(0xffcc00);        square.drawRect(0, 0, 32, 32);        square.x = i * 32;        square.y = Math.floor(i / 10) * 32;        squares[i] = square;    }}
So I'm trying something really simple, drawing some squares and positioning them in two consecutive rows at the top of the screen.

Setting the second row's y positions doesn't work though. I'm using Math.floor(i / 10) * 32 which always traces the correct value (0 for first row, 32 for second) but the second row of squares y positions are getting set to 0, not 32. 


If I remove the line

square.x = i * 32; 

the squares y positions are set correctly. Adding that line back in sets the x positions correctly but not the y positions. What the hell is going on?

Happy for people to tell me I'm an idiot, but the code looks ok to me.

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...