locked
Help needed with windows mobile game in C# RRS feed

  • Question

  • I have an image in a game that the user is able to see once the game loads. I have achieved till here.
    There is already timer1 on the form. I tried using timer1 to make the image disappear but it doesn't work.
    *After one second, I want the image to disappear.(how can I do this?)
    Thanks for the help.
    private Image catImage = null;
    private Rectangle catRectangle;
    public Form1()
            {
                InitializeComponent();
                System.Reflection.Assembly execAssem = System.Reflection.Assembly.GetExecutingAssembly();
    
       catImage = new System.Drawing.Bitmap(execAssem.GetManifestResourceStream(@"Blink.cat.gif"));
                catRectangle = new Rectangle(25, 25, catImage.Width, catImage.Height);
                catRectangle = new Rectangle(25, 25, 40, 60);
    
      this.timer1.Enabled = true;
    
    }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                updatePositions();
                Invalidate();
    
            }
    private void Form1_Load(object sender, EventArgs e)
            {
    
            }
            private Bitmap backBuffer = null;
            
          
            private void Form1_Paint(object sender, PaintEventArgs e)
            {
                if (backBuffer == null)
                {
                    backBuffer = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
                }
                using (Graphics g = Graphics.FromImage(backBuffer))
                {
                    g.Clear(Color.Black);
                    g.DrawImage(catImage, catRectangle.X, catRectangle.Y);
    
                   e.Graphics.DrawImage(backBuffer, 0, 0);
    
                }
            }
            
            protected override void OnPaintBackground(PaintEventArgs pevent)
            {
                //Don't allow the background to paint
            }
    Monday, September 28, 2009 8:57 PM

Answers

  • Heya,

    At quick glance have you tried a global flag?

    Assuming you want to use your timer solution you could do the following:

    (Some pseudo)

    private bool myFlag;

    - Form1() 
    -> myFlag = true; // initialise flag
    -> enable timer

    - Timer1_Tick() // (n) seconds just flew by...
    -> myFlag = false; // disable image now...

    - Form1_Paint() -> if(myFlag) -> Draw Cat (else) -> Don't Draw

    There are many other ways to render images for games, maybe investigate a game loop?

    (Some pseudo)

    - Form1()
    -> display loading screen...
    -> init graphics / game logic...
    -> while (this.Focused)
    -> {
    -> // game logic...
    ->  Application.DoEvents();
    -> }


    Best Regards, D.
    • Marked as answer by warrentang Monday, October 5, 2009 3:16 AM
    Monday, September 28, 2009 11:14 PM