Repos

MELHARFI-2D-Game-Engine.

Got to repo.

10. Mouse events

Mouse Events

Time to add some interactions with our objects.

Each drawing class (Bmp,Anim,Rec,Txt) inherit from an Interface called IGfx, the particular job of this interface is to make all inherited classes got something in common, and guess what !! all those classes has same events and some stuff like Name, Tag, Visible, Z-Index but we are going to see only events right now

  • MouseClic
  • MouseDoubleClic
  • MouseDown
  • MouseUp
  • MouseOver
  • MouseMove
  • MouseOut
  • To bind an object to an event just follow your object name by "".MouseClic +=" and then intellisense ask you if you want to auto generate a method using the "Tab" button.

                            
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using MELHARFI.Manager;
    using MELHARFI.Manager.Gfx;
    
    namespace _2dProject
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
    
                Manager manager = new Manager(this, "CORE_ENGINE");
                manager.Background = Color.Blue;
    
                Bmp cloudPicture = new Bmp("cloud.png", new Point(0, 0), manager);
                cloudPicture.MouseClic += CloudPicture_MouseClic;
                manager.BackgroundLayer.Add(cloudPicture);
    
            }
    
            private void CloudPicture_MouseClic(Bmp bmp, MouseEventArgs e)
            {
                MessageBox.Show("Cloud has been clicked");
            }
        }
    }
                            
                          

    Services

    App Developpement

    Want me to dev an app for you ? dont hesitate to contact me.

    Programming

    Are you looking for a coder/teammate for your project ? Let's give it a try.

    Job Invitation

    Have a proposal for me ? we can discuss about it.

    Donation maybe ?!

    You want to buy me a coffe ? m.elharfi@gmail.com