Main Menu

PlayBasicFX Screen Shot Updates

Started by kevin, February 16, 2007, 11:45:46 AM

Previous topic - Next topic

kevin

#45
  Machine Code Execution Experiment

      The following picture is taken from a recent dynamic recompilation experiment - I want to stress that the result at this point, is purely for curiously sake and should not be considered as a coming feature in the short term!     

      In this picture the code is doing a brute force fill (PB sample code bellow).  Where it's drawing  a full  screen of individually coloured pixels.    Unlike a normal PlayBasic program, this sample is not running the entire filler code through PlayBasic current VM#1 runtime,   rather it generates a native x86 Machine Code equivalent and executes that.   


; This is the what the fill loop is doing

                       ThisIMage=0
rendertoimage Thisimage
lockbuffer
t=timer()
imageptr=GetIMagePtr(Thisimage)
imagepitch=GetIMagePitch(Thisimage)
CodePtr=GetBankPtr(CodeBank)
For ylp=0 to GetImageHeight(Thisimage)-1
RowAddress=IMagePtr+(ylp*ImagePitch)
for Address=RowAddress to RowAddress+((getimagewidth(ThisImage)-1) * 4) step 4
  Pokeint Address,Colour
Colour=Colour+$11
next
next
tt2#=tt2#+(timer()-t)
unlockbuffer




   Speed wise, there's a obviously going to be a world of difference.   The native machine code version can fill the 800*600*4 screen (1.9meg of data)  in 2->3 milliseconds.    The runtime equivalent struggles at 150ms for the same task.    This is a little misleading  as the VM#1  runtime sees the above inner loop code (above) is low priority opcodes.   So execution of that particular loop is much slower than just using dot fill of the screen.    Which can be done  3 times faster than the poke solution above..    Even so,  the machine code test is approximately 15 ->20times quicker than the fastest VM friendly loop in the runtime.
   
 

kevin

#46
 PB1.70h

      Here's another newly exposed command QuadHitShape - It allows you detect intersections between a convex 4 sided polygon (a quad) and a shape.  Previously it was only a part of the math engine.






MyShape3=NewConvexShape(100,10)
MyShape4=NewConvexShape(70,5)

MergeShape MyShape3,MyShape4

type Tpoint
x#,y#,z#
endtype

Dim Points(4) as tpoint


Do

Cls RGB(0,0,0)

x=GetSCreenWidth()/2
y=GetSCreenHeight()/2

RotateShape myshape4,angle#,2

ShapeXpos#=400
ShapeYpos#=300


mx=mousex()
my=mousey()

Baseangle#=wrapangle(baseangle#,0.01)

for lp=0 to 3
angle2#=wrapangle(baseangle#,90*lp)
Points(lp).x=mx+(CosRadius(Angle2#,100*scaler#))
Points(lp).y=my+(SinRadius(Angle2#,100*scaler#))
next


for lp=0 to 3
lp2=lp+1
if lp=3 then lp2=0
line Points(lp).x,Points(lp).y,Points(lp2).x,Points(lp2).y
next



if Scaler#=<0 then Scaler#=1
if LeftMousebutton()
Scaler#=scaler#+0.01
endif
if RightMousebutton()
Scaler#=scaler#-0.01
endif

result=QuadHitShape( Points(0).x,Points(0).y,_
Points(1).x,Points(1).y,_
Points(2).x,Points(2).y,_
Points(3).x,Points(3).y,_
MyShape4,ShapeXpos#,ShapeYpos#)

if result
Ink rgb(255,0,0)
print "HITSHAPE"
Else
Ink RGB(255,255,255)
print "Missed Shape"
EndIF

DrawShape MyShape4,ShapeXpos#,ShapeYpos#,2
ink 255

angle#=WrapAngle(angle#,0.01)

anglex#=WrapAngle(anglex#,0.11)
angley#=WrapAngle(angley#,0.22)
anglez#=WrapAngle(anglez#,0.23)

print fps()

Sync
loop


kevin

#47
PB1.70  Draw Mode Support in Light + Phong Image

  This is a small change in PB1.70.  Now if you use Light & Phong image now use the current inkmode.   So it can blend the lit pixel with the existing pixel. 



Width=800
Height=600

srcimg=loadnewimage("D:\Play_Basic\ScreenShots\PB_ForestBlast_V012.JPG")
preparefximage srcimg

   img=NewfXImage(Width,height)
FallOffRate=1.5

PhongColour=RndRGB()
For Brightness=0 to 2256 step 8
   rendertoimage img
Cls rgb(255,255,255)
copyrect srcimg,0,0,width,height,img,0,0

inkmode 1+128

;   LightImage Img, Width/2, Height/2, Brightness, FallOffRate
renderPhongImage img,width/2,height/2,PhongColour,brightness,falloffrate 
inkmode 1

if Spacekey() then PhongColour=RndRGB()

rendertoscreen
cls 0
drawimage img,00,00,false
print Brightness
Sync
next

  print "done"
Waitkey

 

kevin

Sprite Collision - Point Hit Sprite

   Point hit sprite now support entity sprites..






Create3DImage 2,32,32

width=GetImageWidth(2)
Height=GetImageHeight(2)
   Cls rgb(22,100,0)
box 0,0,width-1,height-1,false
   GetIMage 2,0,0,Width,Height 


me= MakeParticleSprite(2,rndrange(100,700),rndrange(100,500),5)
;rndrange(10,20))
spritecollisiondebug me,true
spritecollisionMode me,1

;Setfps 75   
Do

Cls rgb(100,200,300)

DrawAllSprites

mx=mousex()
my=mousey()

Circle mx,my,5,false

result=PointHitSprite(mx,my,me)
print result
if result
print "Point Hit Face"
else
print "Missed"
endif

; boxc 0,0,50,20,true,rgb(0,0,0)
print fps()

Sync
loop




Function MakeParticleSprite(ThisIMage,Xpos#,Ypos#,points)

ThisSprite=NewSprite(Xpos#,Ypos#,ThisIMage)

SpriteDRawMOde ThisSprite, 2 ;+16

SpriteVertexQuantity thisSprite,(Points+1)*4
SpriteFaceQuantity thisSprite,(Points+1)

angleStep#=360.0/points
size=32

For lp=0 to points-1
angle#=wrapangle(angle#,anglestep#)
Radius#=100
SetVerts(ThisSprite,VertexOffset,Angle#,Radius#,Size,wrapangle(angle#,-45))
SetFace(ThisSprite,ThisFace,VertexOffset,RndRgb())
VertexOffset=VertexOffset+4
inc thisface
next


EndFUnction ThisSPrite


Function SetVerts(ThisSprite,VertexOffset,Angle#,Radius,Size,Rotation)

CenterX#=CosNewValue(0,angle#,Radius)
CenterY#=SinNewValue(0,angle#,Radius)


For lp=0 to 3
X#=CosNewValue(CenterX#,Rotation,Size)
Y#=SinNewValue(CenterY#,Rotation,Size)
PokeSpriteVertex ThisSprite,VertexOffset,X#,y#,z#
Rotation=wrapangle(Rotation,90)
inc VertexOffset
next

EndFunction


Function SetFace(ThisSprite,ThisFace,VertexOffset,ThisColour)
PokeSpriteFaceVerts ThisSprite,ThisFace,4
PokeSpriteface ThisSprite,ThisFace,0,VertexOffset+0,0,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,1,VertexOffset+1,1,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,2,VertexOffset+2,1,1,ThisColour
PokeSpriteface ThisSprite,ThisFace,3,VertexOffset+3,0,1,ThisColour
EndFunction




kevin


Ray Hit Sprite

   Slowing converting more of the collision frame work,  this picture show that you can now run ray intersection upon Entity sprites.





Create3DImage 2,32,32

width=GetImageWidth(2)
Height=GetImageHeight(2)
   Cls rgb(22,100,0)
box 0,0,width-1,height-1,false
   GetIMage 2,0,0,Width,Height 


me= MakeParticleSprite(2,rndrange(100,700),rndrange(100,500),5)
spritecollisiondebug me,true
spritecollisionMode me,1

Do

Cls rgb(100,200,300)


turnsprite me,0.1
DrawAllSprites

mx=mousex()
my=mousey()

if Mousebutton()=1
RayX1=mx
RayY1=my
endif

line rayx1,rayy1,mx,my
circle Rayx1,rayy1,3,true
result=RayHitSprite(rayx1,rayy1,mx,my,me)
if result
print "Line Hit Sprite"
circle GetIntersectx#(0),GetIntersecty#(0),5,true

ix=GetIntersectx#(0)
iy=GetIntersecty#(0)
ix2=ix+(GetNormalx#(0)*20)
iy2=iy+(GetNormaly#(0)*20)
line ix,iy,ix2,iy2

else
print "Line Missed Sprite"
endif

print fps()

Sync
loop





Function MakeParticleSprite(ThisIMage,Xpos#,Ypos#,points)

ThisSprite=NewSprite(Xpos#,Ypos#,ThisIMage)

SpriteDRawMOde ThisSprite, 2 ;+16

SpriteVertexQuantity thisSprite,(Points+1)*4
SpriteFaceQuantity thisSprite,(Points+1)

angleStep#=360.0/points
size=32

For lp=0 to points-1
angle#=wrapangle(angle#,anglestep#)
Radius#=100
SetVerts(ThisSprite,VertexOffset,Angle#,Radius#,Size,wrapangle(angle#,-45))
SetFace(ThisSprite,ThisFace,VertexOffset,RndRgb())
VertexOffset=VertexOffset+4
inc thisface
next



EndFUnction ThisSPrite


Function SetVerts(ThisSprite,VertexOffset,Angle#,Radius,Size,Rotation)

CenterX#=CosNewValue(0,angle#,Radius)
CenterY#=SinNewValue(0,angle#,Radius)


For lp=0 to 3
X#=CosNewValue(CenterX#,Rotation,Size)
Y#=SinNewValue(CenterY#,Rotation,Size)
PokeSpriteVertex ThisSprite,VertexOffset,X#,y#,z#
Rotation=wrapangle(Rotation,90)
inc VertexOffset
next

EndFunction


Function SetFace(ThisSprite,ThisFace,VertexOffset,ThisColour)
PokeSpriteFaceVerts ThisSprite,ThisFace,4
PokeSpriteface ThisSprite,ThisFace,0,VertexOffset+0,0,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,1,VertexOffset+1,1,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,2,VertexOffset+2,1,1,ThisColour
PokeSpriteface ThisSprite,ThisFace,3,VertexOffset+3,0,1,ThisColour
EndFunction


kevin


Rect Hit Sprite

   This one now support entity sprites also. 



Create3DImage 2,32,32

width=GetImageWidth(2)
Height=GetImageHeight(2)
   Cls rgb(22,100,0)
   GetIMage 2,0,0,Width,Height 

me= MakeParticleSprite(2,rndrange(100,700),rndrange(100,500),5)
Spritecollisiondebug me,true
SpriteCollisionRadius me,100

Do

Cls rgb(100,200,300)

Turnsprite Me,0.1
DrawAllSprites

mx=mousex()
my=mousey()

if Mousebutton()=1
RayX1=mx
RayY1=my
endif

print "Mode:"+Str$(getSpriteCollisionMode(me))

result=RectHitSprite(rayx1,rayy1,mx,my,me)

box rayx1,rayy1,mx,my,false

if result
print "Rect Hit Sprite"
boxc rayx1,rayy1,mx,my,false,$ff0000
else
print "Rect Missed Sprite"
endif

If EnterKey()
r=GetspritecollisionMode(me)+1
if r>6 then r=0
spritecollisionMode me,r
flushkeys
EndIf

print fps()

Sync
loop





Function MakeParticleSprite(ThisIMage,Xpos#,Ypos#,points)

ThisSprite=NewSprite(Xpos#,Ypos#,ThisIMage)

SpriteDrawMode ThisSprite, 2 ;+16
SpriteVertexQuantity thisSprite,(Points+1)*4
SpriteFaceQuantity thisSprite,(Points+1)

angleStep#=360.0/points
size=32

For lp=0 to points-1
angle#=wrapangle(angle#,anglestep#)
Radius#=100
SetVerts(ThisSprite,VertexOffset,Angle#,Radius#,Size,wrapangle(angle#,-45))
SetFace(ThisSprite,ThisFace,VertexOffset,RndRgb())
VertexOffset=VertexOffset+4
inc thisface
next
EndFunction ThisSPrite




Function SetVerts(ThisSprite,VertexOffset,Angle#,Radius,Size,Rotation)

CenterX#=CosNewValue(0,angle#,Radius)
CenterY#=SinNewValue(0,angle#,Radius)


For lp=0 to 3
X#=CosNewValue(CenterX#,Rotation,Size)
Y#=SinNewValue(CenterY#,Rotation,Size)
PokeSpriteVertex ThisSprite,VertexOffset,X#,y#,z#
Rotation=wrapangle(Rotation,90)
inc VertexOffset
next

EndFunction


Function SetFace(ThisSprite,ThisFace,VertexOffset,ThisColour)
PokeSpriteFaceVerts ThisSprite,ThisFace,4
PokeSpriteface ThisSprite,ThisFace,0,VertexOffset+0,0,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,1,VertexOffset+1,1,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,2,VertexOffset+2,1,1,ThisColour
PokeSpriteface ThisSprite,ThisFace,3,VertexOffset+3,0,1,ThisColour
EndFunction



 

kevin

#51
Polygon Hit Sprite

  Quad polygon now supports entity sprites also. This pretty much completes the rewrite of the vector side of the collision engine (code wise), just a matter of hooking stuff back up and culling some any redundant code now.




Create3DImage 2,32,32

width=GetImageWidth(2)
Height=GetImageHeight(2)
   Cls rgb(22,100,0)
   GetIMage 2,0,0,Width,Height 

me= MakeParticleSprite(2,rndrange(100,300),rndrange(100,500),5)
Spritecollisiondebug me,true
SpriteCollisionRadius me,100

Type Vert
X#,y#
endtype
Dim POly(4) as Vert


Do

Cls rgb(100,200,300)

Turnsprite Me,0.1
DrawAllSprites

mx=mousex()
my=mousey()


print "Mode:"+Str$(getSpriteCollisionMode(me))


if mousebutton() then Scaler#=Scaler#+0.01

if Scaler#=0 then Scaler#=0.5
if Scaler#>10 then Scaler#=0.5

For lp=0 to 3
Angle2#=wrapangle(Angle#,(lp*90))
Poly(lp).x=(mx+Cosradius(angle2#,50*Scaler#))
Poly(lp).y=(my+Sinradius(angle2#,50*Scaler#))
next


Angle#=wrapangle(Angle#,0.1)

result=QuadHitSprite(Poly(0).x,Poly(0).y,_
Poly(1).x,Poly(1).y,_
Poly(2).x,Poly(2).y,_
Poly(3).x,Poly(3).y,_
me)

if result
print "Quad Hit Sprite"
HitColour=rgb(255,0,0)

else
HitColour=rgb(255,255,255)
print "Quad Missed Sprite"
endif


DRawPoly(HitColour)

If EnterKey()
r=GetspritecollisionMode(me)+1
if r>6 then r=0
spritecollisionMode me,r
flushkeys
EndIf

print fps()

Sync
loop



Function DRawPoly(HitColour)
For lp=0 to 3
lp2=(lp+1) and 3
linec Poly(lp).x,Poly(lp).y,Poly(lp2).x,Poly(lp2).y,HitColour
next
EndFUnction

Function MakeParticleSprite(ThisIMage,Xpos#,Ypos#,points)

ThisSprite=NewSprite(Xpos#,Ypos#,ThisIMage)

SpriteDrawMode ThisSprite, 2 ;+16
SpriteVertexQuantity thisSprite,(Points+1)*4
SpriteFaceQuantity thisSprite,(Points+1)

angleStep#=360.0/points
size=32

For lp=0 to points-1
angle#=wrapangle(angle#,anglestep#)
Radius#=100
SetVerts(ThisSprite,VertexOffset,Angle#,Radius#,Size,wrapangle(angle#,-45))
SetFace(ThisSprite,ThisFace,VertexOffset,RndRgb())
VertexOffset=VertexOffset+4
inc thisface
next
EndFunction ThisSPrite




Function SetVerts(ThisSprite,VertexOffset,Angle#,Radius,Size,Rotation)

CenterX#=CosNewValue(0,angle#,Radius)
CenterY#=SinNewValue(0,angle#,Radius)


For lp=0 to 3
X#=CosNewValue(CenterX#,Rotation,Size)
Y#=SinNewValue(CenterY#,Rotation,Size)
PokeSpriteVertex ThisSprite,VertexOffset,X#,y#,z#
Rotation=wrapangle(Rotation,90)
inc VertexOffset
next
EndFunction


Function SetFace(ThisSprite,ThisFace,VertexOffset,ThisColour)
PokeSpriteFaceVerts ThisSprite,ThisFace,4
PokeSpriteface ThisSprite,ThisFace,0,VertexOffset+0,0,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,1,VertexOffset+1,1,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,2,VertexOffset+2,1,1,ThisColour
PokeSpriteface ThisSprite,ThisFace,3,VertexOffset+3,0,1,ThisColour
EndFunction


kevin

Sprites OverLap

    In this demo we're detecting overlaps between two entity level sprites.   With this addition, this almost restores all of the vector level sprite collision support from PB1.63.  Still a few tidbits left to do before updating the Pixel Perfect stuff.    But it won't be too long now :)






Create3DImage 2,32,32

width=GetImageWidth(2)
Height=GetImageHeight(2)
   Cls rgb(22,100,0)
   GetIMage 2,0,0,Width,Height 

me= MakeParticleSprite(2,rndrange(100,300),rndrange(100,500),5)
Spritecollisiondebug me,true
SpriteCollisionRadius me,100

you= MakeParticleSprite(2,rndrange(200,600),rndrange(100,500),7)
Spritecollisiondebug you,true
SpriteCollisionRadius you,200



Type Vert
X#,y#
endtype
Dim POly(4) as Vert


Do

Cls rgb(100,200,300)

mx=mousex()
my=mousey()
positionsprite me,mx,my
Scalesprite me,scaler#
Turnsprite Me,0.1
DrawAllSprites


mode=getSpriteCollisionMode(me)
print " Src Mode:"+Str$(mode)+"  "+CollName(Mode)
mode=getSpriteCollisionMode(you)
print "Dest Mode:"+Str$(mode)+"  "+CollName(Mode)


if mousebutton() then Scaler#=Scaler#+0.01

if Scaler#=0 then Scaler#=0.5
if Scaler#>10 then Scaler#=0.5

result=spritesoverlap(Me,you)
if result
print "Sprites Overlap"
HitColour=rgb(255,0,0)

else
HitColour=rgb(255,255,255)
print "Sprites Don't OverLap"
endif


k$=lower$(inkey$())
If k$="m"
DumpSpriteMode(me)
flushkeys
EndIf

If k$="y"
DumpSpriteMode(you)
flushkeys
EndIf
print fps()

Sync
loop




Function  DumpSpriteMode(ThisSprite)
r=GetspritecollisionMode(ThisSprite)+1
if r>6 then r=0
spritecollisionMode ThisSprite,r
EndFunction

Function MakeParticleSprite(ThisIMage,Xpos#,Ypos#,points)

ThisSprite=NewSprite(Xpos#,Ypos#,ThisIMage)

SpriteDrawMode ThisSprite, 2 ;+16
SpriteVertexQuantity thisSprite,(Points+1)*4
SpriteFaceQuantity thisSprite,(Points+1)

angleStep#=360.0/points
size=32

For lp=0 to points-1
angle#=wrapangle(angle#,anglestep#)
Radius#=100
SetVerts(ThisSprite,VertexOffset,Angle#,Radius#,Size,wrapangle(angle#,-45))
SetFace(ThisSprite,ThisFace,VertexOffset,RndRgb())
VertexOffset=VertexOffset+4
inc thisface
next
EndFunction ThisSPrite




Function SetVerts(ThisSprite,VertexOffset,Angle#,Radius,Size,Rotation)

CenterX#=CosNewValue(0,angle#,Radius)
CenterY#=SinNewValue(0,angle#,Radius)


For lp=0 to 3
X#=CosNewValue(CenterX#,Rotation,Size)
Y#=SinNewValue(CenterY#,Rotation,Size)
PokeSpriteVertex ThisSprite,VertexOffset,X#,y#,z#
Rotation=wrapangle(Rotation,90)
inc VertexOffset
next

EndFunction


Function SetFace(ThisSprite,ThisFace,VertexOffset,ThisColour)
PokeSpriteFaceVerts ThisSprite,ThisFace,4
PokeSpriteface ThisSprite,ThisFace,0,VertexOffset+0,0,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,1,VertexOffset+1,1,0,ThisColour
PokeSpriteface ThisSprite,ThisFace,2,VertexOffset+2,1,1,ThisColour
PokeSpriteface ThisSprite,ThisFace,3,VertexOffset+3,0,1,ThisColour
EndFunction


Function CollName(Mode)
Select mode
case 0 : name$="Rect"
case 1 : name$="Mesh"
case 2 : name$="Circle"
case 3 : name$="Shape"
case 4 : name$="Slide"
case 5 : name$="Sticky"
case 6 : name$="Pixel"
endselect

EndFunction name$







kevin

  PB1.70k CircleHitSprite (ShapeMode)

     Restored most of the shape mode vector collision methods today.   With any luck, I might be able to finish those all today..   

     For example code See  Projects\Sprites\Collision folder.

kevin

#54
  PB1.70k QuadHitSprite (ShapeMode)
       
       Well, it's just about the end of another long day and Beta K is moving along nicely. Haven't got all of the vector collision done.  Found a few missing tidbits that needed to be replaced, due to changing to the mesh library.  Probably should have documented how the original version worked at the time :)     

       The pic is just one of the sprite collision examples. (from your example pack)  About 50% of them are working as per PB1.63 now. 

kevin


PB1.70k ShapeHitSprite (ShapeMode)

    Shape Hit Sprite is working again.



kevin


Video Feedback

     Here's another video feedback variation in PB1.70




LoadFont  "Arial",1,75,0

Surf1=New3Dimage(GetScreenWidth(),GetScreenHeight())

CurrentCol =RndRgb()
NextCol =RndRgb()

Setfps 60
Do

sw=GetScreenWidth()/2
sh=GetScreenHeight()/2
scale#=1.7
angle#=wrapangle(angle#,0.11)

DRawRotatedIMage  Surf1,sw,sh,angle#,scale#,scale#,sw*-1,sh*-1,false
CopyRect 0,0,0,GetScreenWidth(),GetSCreenHeight(),surf1,0,0

DRawAlphaIMage  Surf1,1,1,0.55,true

ink rgbalphablend(CurrentCol,NextCol,Blend)
CenterText mousex(),mousey(),"PlayBasic V1.70"

inc blend
if blend>100
blend=0
CurrentCol=NextCol
NextCol=RndRgb()
endif

CopyRect 0,0,0,GetScreenWidth(),GetSCreenHeight(),surf1,0,0

Sync

loop


kevin


PB1.70l PointHitSpritePixels (PixelPerfectMode)

       In 1.70L i'm slowly restoring the pixel perfect sprite collision modes.  The main change is that now support entity (mesh based) sprites.   The following pictures are just taken from PointHitSpritePixels demo (See projects\Sprites\Collision) from the examples pack however.   There's two shots in the pic A the point is inside the sprite but missing the pixels, and in the pic B the point is hitting the pixels.. Although it's a little hard to see.  But ya get that :)




kevin

  PB170l  PointHitSpritePixels 1500 Rotating Scaling sprites

        Here's an example of running the new PointHitSpritePixels function on a 1500 sprite scene.   



; Load a Ship image and prepare it for 3D (rotation)
Load3DImage "..\..\..\..\gfx\ship.bmp",1
rgbmaskimage 1,$ffffff

; get the images width + height
w=GetImageWidth(1)
h=GetImageHeight(1)

; Set the Max number of sprites in this test
max=1500
Dim Sprites(MAx)

For lp=1 To max

; create a new sprite, and give it a random X & Y position
Spr2 =NewSprite(Rnd(800),Rnd(600),1)
; set the sprites drawmode to rotated (mode 2)
SpriteDrawMode spr2,2

; Turn Sprite Collision OFF - as were manually checking for collisions bellow
SpriteCollision spr2, off

; center sprite handle
CenterSpriteHandle spr2

; randomly scale the sprite
ScaleSprite Spr2,RndRange#(1,2)

Sprites(lp)=spr2
Next



; Start of program Main loop
Do
; clear the screen to RGB colour 100,100,100
Cls RGB(100,100,100)

; Get the Mouse Position
mX=MouseX()-1
mY=MouseY()-1

; run Through and check if this point is over a sprite
For lp=1 To max

; get the sprite index
Spr2=Sprites(lp)
Turnsprite Spr2,(lp*0.05)

; reset this sprites draw mode to mode 2 - rotated
SpriteDrawMode spr2,2

; Check if this point hits this sprites pixels
If PointHitSpritePixels(mx,my,spr2,0.5)


; set the sprite to a red colour

pokeSpritefacergb Spr2,0,0,$ff0000
pokeSpritefacergb Spr2,0,1,$ff0000
pokeSpritefacergb Spr2,0,2,$ff0000
pokeSpritefacergb Spr2,0,3,$ff0000

else
pokeSpritefacergb Spr2,0,0,$ffffff
pokeSpritefacergb Spr2,0,1,$ffffff
pokeSpritefacergb Spr2,0,2,$ffffff
pokeSpritefacergb Spr2,0,3,$ffffff


EndIf

Next

; draw all the sprites
DrawAllSprites

; draw the mouse position
boxc mx,my,mx+2,my+2,true,rndrgb()

s$=str$(fps())
boxc xpos,ypos,xpos+GetTExtWidth(s$),ypos+GetTExtHeight(s$),true,0
Text xpos,ypos,s$


; refresh the display
Sync

; loop back to the DO statement and continue this program
Loop






kevin


  PB170l  Running RectHitSpritePixels 1500 Rotating Scaling sprites

       This example of running RectHitSpritePixels function on a 1500 sprite scene.   







  ; -----------------------------------------------------------
  ;               >>>>> RECT Hit Sprite Pixels <<<<<<<
  ; -----------------------------------------------------------

; Load a Ship image and prepare it for FX (rotation)
Load3DImage "..\..\..\..\gfx\ship.bmp",1
rgbmaskimage 1,$ffffff

; get the images width + height
w=GetImageWidth(1)
h=GetImageHeight(1)

; Set the Max number of sprites in this test
max=1500
Dim Sprites(MAx)

For lp=1 To max

; create a new sprite, and give it a random X & Y position
Spr2 =NewSprite(Rnd(800),Rnd(600),1)

; set the sprites drawmode to rotated (mode 2)
SpriteDrawMode spr2,2

; Turn Sprite Collision OFF - as were manually checking for collisions bellow
SpriteCollision spr2, off

;l SpriteCollisionMode spr2, 6
; SpriteCollisionDebug spr2,true


; center sprite handle
CenterSpriteHandle spr2

; randomly scale the sprite
ScaleSprite Spr2,RndRange#(1,2)

Sprites(lp)=spr2
Next



; Start of program Main loop
Do
; clear the screen to RGB colour 100,100,100
Cls RGB(100,100,100)


; Get the Mouse Position
mX=MouseX()
mY=MouseY()

Width=100
Height=200

rectx1=mx-(width/2)
recty1=my-(height/2)

rectx2=mx+(width/2)
recty2=my+(height/2)

; run Through and check if this point is over a sprite
For lp=1 To max

; get the sprite index
Spr2=Sprites(lp)
Turnsprite Spr2,(lp*0.05)

; Check if this point hits this sprites pixels
If RectHitSpritePixels(rectx1,recty1,rectx2,recty2,spr2,1)

pokeSpritefacergb Spr2,0,0,$ff0000
pokeSpritefacergb Spr2,0,1,$ff0000
pokeSpritefacergb Spr2,0,2,$ff0000
pokeSpritefacergb Spr2,0,3,$ff0000

else
pokeSpritefacergb Spr2,0,0,$ffffff
pokeSpritefacergb Spr2,0,1,$ffffff
pokeSpritefacergb Spr2,0,2,$ffffff
pokeSpritefacergb Spr2,0,3,$ffffff
EndIf
Next

; draw all the sprites
DrawAllSprites



; draw the mouse position
boxc rectx1,recty1,rectx2,recty2,false,rgb(200,0,200)

s$=str$(fps())
boxc xpos,ypos,xpos+GetTExtWidth(s$),ypos+GetTExtHeight(s$),true,0
Text xpos,ypos,s$


; refresh the display
Sync

; loop back to the DO statement and continue this program
Loop