Main Menu

MirrorImage

Started by ATLUS, July 27, 2008, 03:04:13 PM

Previous topic - Next topic

ATLUS

Plz help me. me sprite. me need mirrorimage if left or right key presed
Quotesetfps 60
#include "FrameSheetAnims"

ast32frames=loadframesheet("walk.bmp",16,31,-1)
anim1=NewAnim(ast32Frames,7)
Xpos      =300
ypos      =60
do
Cls Rgb(0,0,0)

createsprite 1

SpriteImage 1,GetAnimImage(anim1)
if leftkey()=true then Xpos=Xpos-1: mirrorimage GetAnimImage(anim1),true,false :stepanim(anim1)
if rightkey()=1 then Xpos=Xpos+1:mirrorimage GetAnimImage(anim1),true,false :stepanim(anim1)
positionsprite 1,Xpos,Ypos
drawallsprites
sync
loop

kevin

#1
   If you tweaked your code up a little, you could do it that way, it's just that MIRROR IMAGE (like all image commands) actually changes the images pixel data.   So if you wanted to use the same animation twice for example (i.e. have two characters sharing it for example)  then this will get messy, and not to mention slow.

  Sprite rendering has various draw modes.  By default the DrawMode is set to 'solid' or static render if you like.  This mode is for when you just want to draw the sprite's image  with no translations(scaling/rotation) or pixel effects added.    If you want to Mirror a sprite on the X axis (Which requires translation) we need to set the sprite to a Rotated DrawMode, then we'd Scale the Sprite the negatively on that axis.  This will flip the Sprite's vextexs backwards, so it's image will appear flipped.

  Another thing to note is that FrameSheet Animation library has a private  Global Variable built into it for manually selecting the Type of Images the Frame Sheet should us.   This is currently controlled with the FrameSheetDefaultImageType variable.   If you're going to be to doing lots of rotation and scaling then it's recommended you set this to mode 2 (FX mode).   This will force to FrameSheet library to create FX images rather than Video images.    While you can use either, with FX is the best option for rotation in PBV1.63.

   E.g.
   FrameSheetDefaultImageType =1     ; Default Video Images
   FrameSheetDefaultImageType =2     ; FX Images
 

     Read PlayBASIC HELP on FRAME SHEET ANIMATIONS

PlayBASIC Code: [Select]
setfps 60
#include "FrameSheetAnims"

; Tell Frame Sheet Library to create FX images for use as rotated sprites
FrameSheetDefaultImageType=2

ast32frames=loadframesheet("walk.bmp",16,31,-1)
anim1=NewAnim(ast32Frames,7)
Xpos =300
ypos =60

; CReate the Sprite we'll be using for our character
CreateSprite 1

; set sprite to Rotated mode
SpriteDrawMode 1,2 ; set sprite to rotated mode

; Tell PB to auto center this sprite, so it can be easily mirror/flipped
AutoCenterSpriteHandle 1,true

do
Cls Rgb(0,0,0)

if leftkey()=true
Xpos=Xpos-1
stepanim(anim1)
scalespriteX 1,-1 ; negate scaling to flip sprite on the X axis (LEFT)
endif

if rightkey()=1
Xpos=Xpos+1
stepanim(anim1)
scalespriteX 1,1 ; restore position scaling to flip sprite on the X axis (RIGHT)
endif

SpriteImage 1,GetAnimImage(anim1)

Positionsprite 1,Xpos,Ypos

Drawallsprites

sync
loop




ATLUS

Thank you very match!!!!!!!!!