CreateShape
CreateShape ShapeIndex, NumbOfVertex, NumbOfEdges
 
Parameters:

    ShapeIndex = The Index of the shape you wish to create
    NumbOfVertex = The number of vertex
    NumbOfEdges = The number of edges
Returns: NONE
 

      CreateShape initializes a shapes vertex and edge buffers ready for use. Shapes have a dual purpose in PlayBASIC, you can use them to render filled polygons or for complex collision operations if you like.

      To construct a shape we need two things. First we define a set of points (called vertex). The points are the corners of your shape. Next we join these points together to form the edges of the shape.

      The edges that we connect are assumed to create an enclosed space. But they don't actually have to, as one of the beauties of shapes, is we can pretty much join any points we like together, and the DrawShape command will try and render it.



FACTS:


      * Shape Vertex indexes ranges between Zero and MaxVertex-1

      * Shape Edge indexes ranges between Zero and MaxEdges-1




Mini Tutorial:


      This example creates a shape. First it initializes the shape, then it defines a list of vertex and then connects these points as edges.


  
  
; Define a variable, and grab a free shape Index
  MyShape = GetFreeShape()
  
; Create MySHape, with room for 10 vertex and
; 10 edge connections
  CreateShape MyShape,10,10
  
; Set the 8 vertex positions in this shape
; Set vertex #1, -50x,-50y
  SetShapeVertex MySHape,1,-50,-50
  SetShapeVertex MySHape,2,50,-50
  SetShapeVertex MySHape,3,50,50
  SetShapeVertex MySHape,4,-50,50
  
  SetShapeVertex MySHape,5,-20,-20
  SetShapeVertex MySHape,6,20,-20
  SetShapeVertex MySHape,7,20,20
  SetShapeVertex MySHape,8,-20,20
  
  
; Connect the vertex together to form the edges
; Connect outter edges
  SetShapeEdge MyShape,1,1,2
  SetShapeEdge MyShape,2,2,3
  SetShapeEdge MyShape,3,3,4
  SetShapeEdge MyShape,4,4,1
  
; connect inner edges
  SetShapeEdge MyShape,5,5,6
  SetShapeEdge MyShape,6,6,7
  SetShapeEdge MyShape,7,7,8
  SetShapeEdge MyShape,8,8,5
  
  
; Draw the shapes points
  CenterText 100,20,"Shape Vertex"
  DrawShape MyShape,100,100,0
  
; Draw the outline (edges) of this shape
  CenterText 250,20,"Shape Edges"
  DrawShape MyShape,250,100,1
  
; Draw the Filled shape
  CenterText 400,20,"Filled Shape"
  DrawShape MyShape,400,100,2
  
  Sync
  WaitKey
  
  



      This example outputs,





 
Related Info: CreateConvexShape | GetFreeShape | LoadShape | NewConvexShape | NewShape | SaveShape | SpriteCollisionMode :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com