SpriteImageUV
SpriteImageUV SpriteIndex, VertexIndex, U, V
 
Parameters:

    SpriteIndex = The Sprite you wish to set
    VertexIndex = The Vertex your wish to alter
    U = The U (X coord) of this texel
    V = The V (Y coord) of this texel
Returns: NONE
 


      SpriteImageUV allows you to change the UV coordinates of the sprites image. Each corner of the sprite has it's own UV coordinate. The U coordinates can be thought of as an X coordinate within the sprites image space, and V is the Y coordinate So setting the sprites UV coordinates allows us to change the region of the image that a sprite is displaying.



FACTS:


      * Sprites are drawn using a 4 sided convex polygons, changing the UV can cause some render errors. So some care is needed.




Mini Tutorial:


      This example creates an random image then applies this image to the screen full of sprites. Each sprites has it's UV coords stepped in, so the sprites will show the various stages of zooming.

  
  
  
; set variable to hold the image width and height
  ImgWidth=100
  ImgHeight=100
  
; First we'll create FX image 1
  CreateFXImage 1,ImgWidth,Imgheight
  
  
; tTll pb to redirect all drawing operations
; to this image
  RenderToImage 1
  
; now we draw 50 randomly sized circles onto the image
  For lp=0 To 50
     CircleC Rnd(ImgWidth),Rnd(ImgHeight),Rnd(20),1,RndRGB()
  Next lp
  
; Tell PB to re-direc all drawing back to the screen
  RenderToScreen
  
  
  MaxSprites=20
  
  pad=80
  y=pad
  x=(pad*2)
  
; Start a For next loop to create a collection of sprites
  For lp=0 To MaxSprites
   ; create a sprite and assign it image #1
     Spr=NewSprite(X,y,1)
     CenterSpriteHandle spr
   ; Set this sprite to Draw Mode #2 (rotated)
     SpriteDrawMode spr,2
     
     clip=lp*5
     
   ; set the 4 UV corners of this sprite
     SpriteImageUV Spr,0,Clip,Clip
     SpriteImageUV Spr,1,ImgWidth-Clip,Clip
     SpriteImageUV Spr,2,ImgWidth-Clip,ImgHeight-Clip
     SpriteImageUV Spr,3,lp,ImgHeight-Clip
     
     DrawSprite Spr
     
   ;
     
     
   ; Read the Sprites Vertex positions
     For Vertex=0 To 3
        Vx#=GetSpriteVertexX(Spr,Vertex)
        Vy#=GetSpriteVertexY(Spr,Vertex)
        u=GetSpriteImageU(Spr,Vertex)
        v=GetSpriteImageV(Spr,Vertex)
        
        s$=Digits$(u,3)+"x,"+Digits$(v,3)+"y"
        CenterText vx#,vy#,s$
     Next vertex
     
     
     
     x=x+200
     If x=>(GetScreenWidth()-pad)
        X=(Pad*2)
        Y=y+200
     EndIf
  Next
  
; Display the Screen and wait for the user to press a key
  Sync
  WaitKey
  
  


 
Related Info: GetSpriteVertexX | GetSpriteVertexY | SpriteDrawMode | SpriteImage | SpriteImageIntensity | SpriteImageRGB :
 


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