Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6728893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:13:26+00:00 2026-05-26T10:13:26+00:00

I could find a set of java 2D game tutorials and android game tutorials

  • 0

I could find a set of java 2D game tutorials and android game tutorials which uses only native graphics libraries.
I’m looking for something similar in C# ( without DirectX or XNA)
I found this game loop skeleton , but it doesn’t tell how to Render the Graphics.

Target is to simulate a simple Electronic device.
I need to show some graphical output as user "presses" some keys on the keyboard quickly.Hence it looks like an arcade game.

For example As the user presses one of the arrow keys a pointer(an image) will move accordingly.

I guess I can’t do this with typical Windows Forms Application can I?
For example use a PictureBox control and move it in KeyPress event of the Form.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:13:27+00:00Added an answer on May 26, 2026 at 10:13 am

    Here’s a simple game using WinForms and a Timer, using Graphics to draw (encapsulates GDI+).

    It adds a timer that ‘ticks’ every 10 milliseconds. Each tick it performs game logic, then draws to an off screen bitmap. This is as opposed to using a continual loop as in the example in the link.

    The form handles key events separately (as opposed to doing something like GetKeyState)

    When the form is resized, and when it first loads it’ll create the backbuffer bitmap of the right size.


    Create a new form and replace all code with below. Control the ball using arrow keys. There’s no notion of dying.

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    namespace WindowsFormsGame
    {
        public partial class Form1 : Form
        {
            Bitmap Backbuffer;
    
            const int BallAxisSpeed = 2;
    
            Point BallPos = new Point(30, 30);
            Point BallSpeed = new Point(BallAxisSpeed, BallAxisSpeed);
            const int BallSize = 50;
    
            public Form1()
            {
                InitializeComponent();
    
                this.SetStyle(
                ControlStyles.UserPaint |
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.DoubleBuffer, true);
    
                Timer GameTimer = new Timer();
                GameTimer.Interval = 10;
                GameTimer.Tick += new EventHandler(GameTimer_Tick);
                GameTimer.Start();
    
                this.ResizeEnd += new EventHandler(Form1_CreateBackBuffer);
                this.Load += new EventHandler(Form1_CreateBackBuffer);
                this.Paint += new PaintEventHandler(Form1_Paint);
    
                this.KeyDown += new KeyEventHandler(Form1_KeyDown);
            }
    
            void Form1_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Left)
                    BallSpeed.X = -BallAxisSpeed;
                else if (e.KeyCode == Keys.Right)
                    BallSpeed.X = BallAxisSpeed;
                else if (e.KeyCode == Keys.Up)
                    BallSpeed.Y = -BallAxisSpeed; // Y axis is downwards so -ve is up.
                else if (e.KeyCode == Keys.Down)
                    BallSpeed.Y = BallAxisSpeed;
            }
    
            void Form1_Paint(object sender, PaintEventArgs e)
            {
                if (Backbuffer != null)
                {
                    e.Graphics.DrawImageUnscaled(Backbuffer, Point.Empty);
                }
            }
    
            void Form1_CreateBackBuffer(object sender, EventArgs e)
            {
                if (Backbuffer != null)
                    Backbuffer.Dispose();
    
                Backbuffer = new Bitmap(ClientSize.Width, ClientSize.Height);
            }
    
            void Draw()
            {
                if (Backbuffer != null)
                {
                    using (var g = Graphics.FromImage(Backbuffer))
                    {
                        g.Clear(Color.White);
                        g.FillEllipse(Brushes.Black, BallPos.X - BallSize / 2, BallPos.Y - BallSize / 2, BallSize, BallSize);
                    }
    
                    Invalidate();
                }
            }
    
            void GameTimer_Tick(object sender, EventArgs e)
            {
                BallPos.X += BallSpeed.X;
                BallPos.Y += BallSpeed.Y;
    
    
                Draw();
    
                // TODO: Add the notion of dying (disable the timer and show a message box or something)
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there tools out there which could automatically find copy-and-paste code among a set
The only instructions I could find are here: http://eigenclass.org/hiki/fast-widefinder and on the old jocaml
I am looking for an algorithm that could find the two most distant elements
I can't find much information on const_cast . The only info I could find
Yesterday i had a question in an interview which i thought i could find
I'm trying to create a memory game. I've looked at the Android tutorials for
I'm looking for an implementation of java.util.Set with the following features: Should be concurrent
From what information I could find, they both solve the same problems - more
Do you know where I could find some useful third party (free) code snippets
Does anybody know where I could find WinForms controls that mimic those on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.