Flashing mobile canvas

I want to move the canvas , and transparent picture , so to achieve the effect of slowly disappear , but when I moved the canvas to flicker

this my code:

Add the action event to the Timer and put in this code.

if iCount < 255 then
Canvas1.Left = Canvas1.Left +10
iCount = iCount + 10
h1.mask.graphics.forecolor= rgb(iCount,iCount,iCount)
h1.mask.graphics.fillrect(0,0,h1.width,h1.height)
canvas1.Invalidate
end if

Add the Paint event to the canvas and put in this code.
g.DrawPicture h1, 0, 0

What operating system are you on? I’ve read many threads here that involve flicker and most of the time it’s on Windows OS. If that’s the case it will be a challenge to get rid of the flicker.

windows…

You might look in to look in to double buffering but I’m not sure it will work. Personally, I have’t been able to get an animated effect on windows without flicker, I even have trouble resizing a window without flicker troubles. If you search the forum for “flicker” you may get some ideas, but you may also become discouraged. Flicker and Windows have been life long friends thus far.

On Windows, you want to make sure that the EraseBackground property of the Canvas is set to false (NO).

In your code, also pass False to Invalidate:

Canvas1.Invalidate(False)

Setting double-buffering on Windows can also help, but I don’t think it will matter for your code.

I wonder if reducing the period of the timer and incrementing the position and opacity by 1, rather than 10, would help.

You will never eliminate flicker if you’re moving the canvas. Make the canvas bigger and move an image inside it. I don’t know how well the DoubleBuffer option works, but I’ve created flicker-free animations on windows using my own buffer image (the size of the canvas - draw everything into the buffer, then draw the buffer to screen with no EraseBackground). It also can improve performance on a complex image, because you don’t have to render everything all the time - just the stuff that changed.

This is not effective

thanks tim ,Depending on your tips, I rewrote the code to achieve the effect
this is my code

  Dim buffer as Picture
  Buffer=NewPicture(a2.Width,a2.Height,Screen(0).Depth)
    do
      if iCount1 < 255 then
        iCount1= iCount1 +1
        h1.mask.graphics.forecolor= rgb(iCount1,iCount1,iCount1)
        h1.mask.graphics.fillrect(0,0,h1.width,h1.height)
        If Buffer <> Nil then
          buffer.Graphics.DrawPicture a2,0,0                      //Backdrop
          buffer.Graphics.DrawPicture h1,iCount1,30      //In A2 moving image
          canvas1.Graphics.DrawPicture buffer,0,0
          //canvas1.Invalidate 
        end if
      else
     
        timer1.Mode = 0
        exit do
      end if
      app.DoEvents
    loop

Great! You can eliminate the loop and the call to DoEvents by using a Timer. Or, since it seems like this code might be IN a timer, using the timer more effectively. Make iCount a global property (or a property of the Window) and do one iteration of the loop each time the timer fires.

Yes, I’m doing this

  Dim buffer as Picture
  Buffer=NewPicture(a2.Width,a2.Height,Screen(0).Depth)
    if iCount1 < 255 then
      iCount1= iCount1 +1
      h1.mask.graphics.forecolor= rgb(iCount1,iCount1,iCount1)
      h1.mask.graphics.fillrect(0,0,h1.width,h1.height)
      If Buffer <> Nil then
        buffer.Graphics.DrawPicture a2,0,0
        buffer.Graphics.DrawPicture h1,iCount1,30
        canvas1.Graphics.DrawPicture buffer,0,0
      end if
    else
         timer1.Mode = 0
    end if
   buffer = nil