Jump to content

Tell me I'm an idiot


dst
 Share

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

 Share

  • Recently Browsing   0 members

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