April 18, 2024, 11:06:46 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


FLIP inside a timer called routine

Started by barry, February 02, 2010, 01:41:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

barry

I have a little test program made from one of the sample programs, to learn how sprites work and it's all working okay.  I can put everything in a timer service routine except the FLIP statement.  When I put flip in the timer routine it locks up the program.  Can anyone shed any light on this?

I've included the source.  If you substitute any 32x32 bitmap and call it bug.bmp it'll run.  Notice the commented out Flip in the update routine.  If I comment the one in the DO loop and uncomment that one it locks up.  As it is now it's fine.

Any comments will be appreciated

Barry

/* dx1.eba - sprite sample */

WINDOW win
speed = 0
width = 640
height = 480
run = 1

'Calculate the correct window size based on the desired client size
WINRECT rc
rc.top = 0:rc.left = 0:rc.right = width:rc.bottom = height
DECLARE IMPORT, AdjustWindowRectEx(pRect as WINRECT, Style as UINT, bMenu as INT, ExStyle as UINT)
AdjustWindowRectEx(rc, @CAPTION|@BORDER,TRUE,@EXWINDOWEDGE)

OPENWINDOW win,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top, _
@NOAUTODRAW,0,"Caption",&handler

IF(ATTACHSCREEN(win,width,height,FALSE) < 0)
MESSAGEBOX win,"Couldn't create DirectX window","Error"
CLOSEWINDOW win
END
ENDIF

BACKPEN BackBuffer,RGB(0,128,128)
FRONTPEN BackBuffer,RGB(255,255,255)

FILLSCREEN RGB(0,128,128)
'WriteText 180,0,"PRESS ESC TO CLOSE, FPS: " + str$(speed)

bug = LoadSprite(GETSTARTPATH+"bug.bmp",0,0,0,TRUE)
IF bug = NULL
MESSAGEBOX win,"Couldn't load mouth.bmp\nMake sure it's in executables path","Error"
CLOSESCREEN
CLOSEWINDOW win
END
END IF
SpriteDrawMode bug,@TRANS
SpriteMaskColor bug,RGB(255,255,255)
SpriteAlpha bug,180
SpriteShadowOffset bug,-5,-5
x = 0
y = 400
xdir = 4
ydir = -4


SpriteDrawMode bug,@TRANSROTOZOOM
STARTTIMER(win, 50)

DO
'play with the sprite
' DrawSpriteXY bug,x,y
'GOSUB update
' DrawSpriteXY bug,x,y

speed = FLIP
UNTIL run = 0 OR KEYDOWN(1)
FREESPRITE bug
CLOSESCREEN
CLOSEWINDOW win
END

SUB handler
SELECT @message
CASE @IDCLOSEWINDOW
run = 0
STOPTIMER(win)

CASE @IDCREATE
CENTERWINDOW win
CASE @IDTIMER
GOSUB update

ENDSELECT
RETURN
ENDSUB

SUB update

FILLSCREEN RGB(0,128,128)
'adjust bug direction
x += xdir
if(x + GetSpriteWidth(bug)) > width | x < 0 THEN xdir = -xdir
y += ydir
if(y + GetSpriteHeight(bug)) > height | y < 0 THEN ydir = -ydir
DrawSpriteXY bug,x,y
' FLIP

RETURN
ENDSUB

LarryMc

Barry

change your do loop to this
DO
   wait
   'speed = FLIP
UNTIL run = 0 OR KEYDOWN(1)

and uncomment the FLIP in your update routine

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

barry