Game Development Reference
In-Depth Information
Displaying Web Pages
In some apps, you might want to browse a web page rather than just download data or a file. In such
a scenario, we use the openURL function. This starts the mobile Safari browser and opens the URL
passed.
openURL(" http://www.oz-apps.com " )
Physics
Like all of the frameworks covered in the topic, Codea uses Box2D for physics. The following
example shows how to create a physics body and then update a display object based on the
position of the physics object:
bouncy = 0.5
function createPhysicsObj(x1, y1, x2, y2)
local temp = physics.body(EDGE, vec2(x1,t1), vec2(x2,y2))
temp.type = STATIC
temp.restitution = bouncy
return bouncy
end
function setup()
ball.physics.body(CIRCLE, 50)
ball.x = WIDTH/2
ball.y = HEIGHT/2
ball.restitution = bouncy
ball.sleepingAllowed = false
createPhysicsObject(0,0,0,HEIGHT)
createPhysicsObject(0,0,WIDTH,0)
createPhysicsObject(WIDTH,0,WIDTH,HEIGHT)
createPhysicsObject(WIDTH,HEIGHT,0,HEIGHT)
end
function draw()
background(40,40,50)
strokewidth(0)
fill(255)
physics.gravity(Gravity)
ellipse(ball.x, ball.y, ball.radius*2)
end
Now as you tilt the device, you can see the ball moving around (see Figure 12-6 ).
 
Search WWH ::




Custom Search