New topic: Question about refresh with pictures
<http://forums.realsoftware.com/viewtopic.php?t=33605> Page 1 of 1 [ 3 posts ] Previous topic | Next topic Author Message SASS Post subject: Question about refresh with picturesPosted: Fri Apr 30, 2010 6:58 am Joined: Mon Dec 28, 2009 10:36 pm Posts: 2 I am really a newbie, but I think this is complicated enough to not belong in that category. My knowledge is based on studying examples, working the tutorials on REALbasic University and trying to decipher the manual, so I am not a savvy as most of you on this board. I'm working on a variation of Chinese Checkers. The programs runs successfully, but it only shows the marble at its end position after each turn. I want it to show the hops. When I step through it, the "highlighted" [not a true highlight, just a different picture] marble hops from hole to hole just as I intended, but when I run the program it does not show the intermediate hops, only the last. Putting in a "wait" didn't make any difference to the marbles--it did delay the "tock" sound, though. I know this has something to do with refresh, but my marbles are pictures that I paint onto the canvas. If I refresh the canvas all the marbles disappear. Here are the routines that are most closely related to my problem: MakeTheJump Code: dim i,j,l,jumps,t,marble,sign as Integer dim s as String dim n as double dim tempx,tempy,nothing as Integer //remove after testimg l=len(JumpPath) jumps=l/5 //successive jumps are held in a string called jumpPath that consists of four digits and a "|" s=JumpPath if jumps<1 then nothing=nothing+1 end //msgbox jumppath for i = 1 to jumps t=val(mid(s,(5*i)-4,4)) gx=t/100 gy=t mod 100 glastx(i-1)=gx glasty(i-1)=gy tempx=gx tempy=gy n=gx-1 gXpos=gRowStart+(n*gRowGap) tempx=gXpos gYpos=gColumnStart + (gy*gColumnGap) tempy=gYpos gPassJump=gJumps-1 window1.EmptyHole Window1.HighlightSelection Tock.Play gPassJump=i-1 Window1.EmptyHole next tempx=gxpos tempy=gypos window1.canvas1.graphics.drawPicture gMarbles(gColor,gPattern),gXpos+gRowGap,gYpos gboard(gx,gy)=gcolor tempx=gx tempy=gy ConvertFromGXY tempx=gcx tempy=gcy sign=1 if gcx<0 then sign=-1 end HighlightSelection Code: dim p as picture p=gHighlight(gColor) canvas1.graphics.drawPicture p,gXpos+gRowGap,gYpos EmptyHole Code: dim lastx,lasty as integer dim j as integer dim n,o as double j=gPassJump if J<0 then j=0 end n=glastx(j) o=glastY(j) lastx=gRowStart+(n*gRowGap) lasty=gColumnStart + (o*gColumnGap) canvas1.graphics.DrawPicture (hex3,lastx,lasty,50,50,lastx,lasty,50,50) gBoard(n,o)=0 I would appreciate any guidance as to what I need to do to see the jumps. Top DaveS Post subject: Re: Question about refresh with picturesPosted: Fri Apr 30, 2010 8:03 am Joined: Sun Aug 05, 2007 10:46 am Posts: 2303 Location: San Diego, CA A CANVAS is non-persistent. Meaning that anything you draw OUTSIDE of its own PAINT event will probably never be seen. Your best bet is do create a PICTURE object the same size as your CANVAS, and do all of your drawing on it. And each time you update the PICTURE object do a CANVAS1.REFRESH And then in the CANVAS.PAINT event ... put ONE LINE OF CODE g.drawpicture myPicture,0,0 where myPicture is the picture object you have been manipulating. _________________ Dave Sisemore MacPro, OSX 10.6.2 RB2009r5.1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top jefftullin Post subject: Re: Question about refresh with picturesPosted: Fri Apr 30, 2010 8:51 am Joined: Wed Nov 15, 2006 3:50 pm Posts: 1510 Location: England Getting the movement smooth may be tricky. I'm sure back in the day, this was just the kind of thing that SpriteSurface was for. Anyway, a couple of tips: dave's method is correct. To get the timing better, you may want to add a timer to the window. When you are ready to begin a transition from one place to the next, start the timer. Every time it fires, update the position of the moving marble and draw it, then refresh the window/canvas. When the last movement is complete, turn the timer off. And you may like to draw a grey semi-transparent circle offset by a few pixels, to look like a 'shadow' area under the moving marble. eg: Draw board Draw fixed marbles. Draw 'shadow marble' at curposx +3,curposy +3 Draw moving marble at curposx,curposy Copy this whole graphic to screen. repeat until the move is complete. _________________ RB2009 R5.1 and RB2008 Mac 10.6 + Windows 7/XP + Ubuntu Linux in Vmware on a Macbook 2.16 Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 3 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
