Class: Tmx::ObjectShape::PolyShape
- Inherits:
-
Object
- Object
- Tmx::ObjectShape::PolyShape
- Includes:
- ShapeDefaults
- Defined in:
- lib/tmx_ext/object_shape.rb
Instance Method Summary collapse
- #match?(object) ⇒ Boolean
-
#poly_vec2s(object) ⇒ Object
A TMX object currently has an array of points in a format list of strings.
- #shape(object) ⇒ Object
Methods included from ShapeDefaults
#default_elasticity, #default_sensor, #default_shape_attach_point
Instance Method Details
#match?(object) ⇒ Boolean
22 23 24 |
# File 'lib/tmx_ext/object_shape.rb', line 22 def match?(object) object.contents['shape'] == 'polygon' end |
#poly_vec2s(object) ⇒ Object
Note:
this assumes that we want to convert the points into a format of vec2s specifically for a CP::Shape::Poly shape.
A TMX object currently has an array of points in a format list of strings. This will convert the points into list of CP::Vec2 objects which can be used to create the proper CP::Shape::Poly for the Object.
44 45 46 47 48 49 |
# File 'lib/tmx_ext/object_shape.rb', line 44 def poly_vec2s(object) object.points.map do |point| x,y = point.split(",").map {|p| p.to_i } CP::Vec2.new(x,y) end.reverse end |
#shape(object) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/tmx_ext/object_shape.rb', line 26 def shape(object) new_shape = CP::Shape::Poly.new(object.body,poly_vec2s(object),default_shape_attach_point) new_shape.collision_type = object.type.to_sym new_shape.e = default_elasticity new_shape.sensor = default_sensor new_shape end |