B2.CircleShape: Difference between revisions

From GiderosMobile
No edit summary
m Text replacement - "</source" to "</syntaxhighlight"
 
(One intermediate revision by the same user not shown)
Line 11: Line 11:
=== Examples ===
=== Examples ===
'''Creating a circle body'''
'''Creating a circle body'''
<source lang="lua">
<syntaxhighlight lang="lua">
--create ball bitmap object from ball graphic
--create ball bitmap object from ball graphic
local ball = Bitmap.new(Texture.new("./ball.png"))
local ball = Bitmap.new(Texture.new("./ball.png"))
Line 27: Line 27:
local fixture = body:createFixture{shape = circle, density = 1.0,  
local fixture = body:createFixture{shape = circle, density = 1.0,  
friction = 0.1, restitution = 0.2}
friction = 0.1, restitution = 0.2}
</source>
</syntaxhighlight>


{|-
{|-

Latest revision as of 16:18, 12 July 2023


Supported platforms:
Available since: Gideros 2011.6
Inherits from: b2.Shape

Description

A circle shape.

Examples

Creating a circle body

--create ball bitmap object from ball graphic
local ball = Bitmap.new(Texture.new("./ball.png"))
--reference center of the ball for positioning
ball:setAnchorPoint(0.5,0.5)
ball:setPosition(x,y)
--get radius
local radius = ball:getWidth()/2
 
--create box2d physical object
local body = world:createBody{type = b2.DYNAMIC_BODY}
body:setPosition(ball:getX(), ball:getY())
body:setAngle(ball:getRotation() * math.pi/180)
local circle = b2.CircleShape.new(0, 0, radius)
local fixture = body:createFixture{shape = circle, density = 1.0, 
friction = 0.1, restitution = 0.2}

Methods

b2.CircleShape.new
b2.CircleShape:set sets the center point and radius

Events

Constants