dst Posted February 1, 2014 Share Posted February 1, 2014 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 linesquare.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 More sharing options...
powerfear Posted February 2, 2014 Share Posted February 2, 2014 I think what you want is square.x = (i % 10) * 32; Link to comment Share on other sites More sharing options...
lordtez Posted February 2, 2014 Share Posted February 2, 2014 Your'e an idiot. Link to comment Share on other sites More sharing options...
dst Posted February 2, 2014 Author Share Posted February 2, 2014 Yep, I'm an idiot. Thanks @powerfear Link to comment Share on other sites More sharing options...
Recommended Posts