Sprite Flip & Sprite Mirror

Started by kevin, November 21, 2004, 10:18:41 AM

Previous topic - Next topic

kevin

I'd forgot all about this, it's been year since most of the sprite engine was written, so that happens.  Anyway this example shows how you can to Mirror and Flip sprites using the SpriteScaleX & SpriteScaleY commands.


PlayBASIC Code: [Select]
; ========================
; Part 1 - Create an image
; ========================

Cls 0

; Create a Little triangle image
Size=50
CreateConvexShape 1,Size*0.50,3
RotateShape 1,30,1
DrawShape 1,Size/2,size/2,2
CircleC size/2,size/2,size/5,1,RndRGB()
CircleC size/4,size/4,size/6,1,RndRGB()

MyImage=GetFreeImage()
GetImage MyImage,0,0,size,size
PrepareFXImage MyImage


; ========================
; Part 2 - Create our sprite
; ========================

; Create the Sprite
CreateSprite 1
; Set sprite Center it's handle on any image
AutoCenterSpriteHandle 1,True
; set this sprite to use the previously created image
SpriteImage 1,MyImage
; set the sprites drawing mode to ROTATION (mode 2)
SpriteDrawMode 1,2
; Position the sprite at 100,100
PositionSprite 1,100,100

; Create a second sprite
CreateSprite 2
; copy the settings from sprite 1, into sprite 2
CopySprite 1,2
; Position the sprite at 350,250
PositionSprite 2,350,250


; Create a sprite
CreateSprite 3
; copy the settings from sprite 1, into sprite 2
CopySprite 1,3
; Use a Negate Scale to FLIP this sprite.
ScaleSpriteX 3,-1
; Position the sprite at 350,250
PositionSprite 3,300,100


; Create a sprite
CreateSprite 4
; copy the settings from sprite 1, into sprite 2
CopySprite 1,4
; Use a Negate Scale to FLIP this sprite.
ScaleSpriteY 4,-1
; Position the sprite at 350,250
PositionSprite 4,400,100


; ========================
; Part 3 - The main Loop
; ========================

; Start a do/loop
Do
; clear the screen
Cls 0

; bump the scaler angle
Angle#=WrapAngle(angle#,1)

; Set Sprites 2's X scaling factor
ScaleSpriteX 2,2+CosRadius(angle#,0.5)

; Set Sprites 2's Y scaling factor
ScaleSpriteY 2,2+SinRadius(angle#,0.5)

; Display the current scaling of this sprite
Print "Sprite Scaling Stuff"
Print "Sprites Scale X:"+Str$(GetSpriteScaleX(2))
Print "Sprites Scale Y:"+Str$(GetSpriteScaleY(2))

; Draw all the created sprites
DrawAllSprites

; Draw the screen
Sync

; Loop back to the DO statement
Loop





tomazmb

Hello Kevin,

I like this demo and I like the way you comment your source code - it's much easier to understand. Thanks.

Have a nice day,

Tomaz
My computer specification:

AMD Athlon 64 2800+
MB ASUS K8V Socket 754 VIA K8T800
SB Audigy 2
3 GB RAM DDR 400 MHz PQI
AGP NVIDIA GeForce 7600GT 256 MB-Club 3D
Windows XP Pro SP2
DirectX 9.0c