So far I have created some very simple graphics and added them to my corona project.



I started off my learning using a tutorial by Hetal on the corona blog. I modified the code until I arrived here:
--Setting up physics
local physics = require("physics")
physics.start()
physics.setGravity(0, 0)
--Setting up extras
local gameUI = require("gameUI")
local dragBody = gameUI.dragBody
--Add the ball
local ball = display.newImage("orange_circle.png")
ball.x = display.contentWidth/2
ball.y = display.contentHeight - ball.contentHeight
physics.addBody(ball, { bounce = 1 })
--Add a block
local block = display.newImage("orange_block.png")
block.x = display.contentWidth/2
physics.addBody(block, "static")
--Contain the ball within the scene
local leftWall = display.newRect(0,0, 1, display.contentHeight)
local topWall = display.newRect(0,0, display.contentWidth, 1)
local rightWall = display.newRect(display.contentWidth -1, 0, 1, display.contentHeight)
local bottomWall = display.newRect(0, display.contentHeight -1, display.contentWidth, 1)
physics.addBody(leftWall, "static",{bounce=0})
physics.addBody(topWall, "static", {bounce = 0})
physics.addBody(rightWall, "static", {bounce = 0})
physics.addBody(bottomWall, "static", {bounce = 0})
-- Setting up event listeners
ball:addEventListener("touch", dragBody)
The two bodies in the scene are physical bodies (using the box2d physics interface provided by corona.) By default however these bodies have a square collision box. So next I want the ball to have a circular collision body.
You can get the entire project files here.
No comments:
Post a Comment