I recently downloaded a trial of Corona, and I'm beginning to love it already. It's so easy to use and the multiplatform capabilities make it even better. Anyways, let's get onto my question.
I just finished following a YouTube tutorial on how to make a game called "Breakout". I was very satisfied with the result, but I was wondering how I could set the walls, ball, and paddle to be solid white. I tried using object:setFillColor(255, 255, 255), but it isn't making it solid white. The colors remained the same as if that line didn't exist.
main.lua
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | require("physics") function main() setUpPhysics() createWalls() createBricks() createBall() createPaddle() startGame() end function setUpPhysics() physics.start() physics.setDrawMode("hybrid") physics.setGravity(0,0) end function createWalls() local wallThickness = display.contentHeight / 64 -- Left Wall local wall = display.newRect(0 , 0, wallThickness, display.contentHeight) physics.addBody(wall, "static", {friction = 0, bounce = 1}) wall:setFillColor(255, 255, 255) -- Right Wall wall = display.newRect(display.contentWidth - wallThickness , 0, wallThickness, display.contentHeight) physics.addBody(wall, "static", {friction = 0, bounce = 1}) wall:setFillColor(255, 255, 255) -- Top Wall wall = display.newRect(0 , 0, display.contentWidth, wallThickness) physics.addBody(wall, "static", {friction = 0, bounce = 1}) wall:setFillColor(255, 255, 255) -- Bottom Wall wall = display.newRect(0 , display.contentHeight - wallThickness, display.contentWidth, wallThickness) physics.addBody(wall, "static", {friction = 0, bounce = 1}) wall:setFillColor(255, 255, 255) wall.type = "Bottom" end function createBricks() local brickWidth = display.contentWidth / 8 local brickHeight = display.contentHeight / 32 local numRows = 4 local numColumns = 6 local topLeft = {x = display.contentWidth / 2 - (brickWidth * numColumns) / 2, y = display.contentWidth / 8} local row local column for row = 0, numRows - 1 do for column = 0, numColumns - 1 do local brick = display.newRect(topLeft.x + (column * brickWidth), topLeft.y + (row * brickHeight), brickWidth, brickHeight) brick:setFillColor(math.random(50, 255), math.random(50, 255), math.random(50, 255)) brick.type = "Destructible" physics.addBody(brick, "static", {friction = 0, bounce = 1}) end end end function createBall() local ballRadius = display.contentWidth / 32 ball = display.newCircle(display.contentWidth / 2, display.contentHeight / 2, ballRadius) ball:setFillColor(255, 255, 255) physics.addBody(ball, "dynamic", {friction = 0, bounce = 1, radius = ballRadius}) ball.collision = function(self, event) if(event.phase == "ended") then if(event.other.type == "Destructible") then event.other:removeSelf() end if(event.other.type == "Bottom") then self:removeSelf() local onTimerComplete = function(event) createBall() startGame() end timer.performWithDelay(0, onTimerComplete, 1) end end end ball:addEventListener("collision", ball) end function createPaddle() local paddleWidth = display.contentWidth / 2.4 local paddleHeight = display.contentHeight / 64 local paddle = display.newRect(display.contentWidth / 2 - paddleWidth / 2, display.contentHeight - display.contentHeight / 9.6, paddleWidth, paddleHeight) physics.addBody(paddle, "static", {friction = 0, bounce = 1}) local movePaddle = function(event) paddle.x = event.x end Runtime:addEventListener("touch", movePaddle) end function startGame() ball:setLinearVelocity(math.random(-150, 150), display.contentWidth / 1.25) end display.setStatusBar(display.HiddenStatusBar) main() |
Hey there,
Comment out line 14; physics.setDrawMode("hybrid")
They ARE white, you're just seeing the physical bodies because you've got that turned on.
Peach :)
Thanks!
No worries.
On a side note, please don't make dupe threads - have deleted the other one. http://developer.anscamobile.com/forum/2011/05/05/forum-rules-and-guidelines
Thank you :)
Peach