Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

*DO NOT* SHARE MEDIA OR LINKS TO LEAKED COPYRIGHTED MATERIAL. Discussion is allowed.

C# error with GTA.GraphicsEventArgs and KeyPressDelegate


TehStranger?
 Share

Recommended Posts

Hey guys, new here :p
I am working on a basic script just out of pure boredom but I ran into a problem, I am trying to get Graphics.DrawText to display the FPS but it causes an error with my BindKey code that toggles it on and off, here is the code:
BindKey(Keys.F7, new KeyPressDelegate(showFPS));
}
public void showFPS(object sender, GTA.GraphicsEventArgs args)
{
string fps = Game.FPS.ToString();
args.Graphics.DrawText(fps, 0.9f, 0.1f);
}

it gives the error "No overload for 'showFPS' matches delegate 'GTA.KeyPressDelegate'"

Any help would be much appreciated, cheers.

Edited by TehStranger?
Link to comment
Share on other sites

 

Hey guys, new here :p
I am working on a basic script just out of pure boredom but I ran into a problem, I am trying to get Graphics.DrawText to display the FPS but it causes an error with my BindKey code that toggles it on and off, here is the code:

 

BindKey(Keys.F7, new KeyPressDelegate(showFPS));
}
public void showFPS(object sender, GTA.GraphicsEventArgs args)
{
string fps = Game.FPS.ToString();
args.Graphics.DrawText(fps, 0.9f, 0.1f);
}

it gives the error "No overload for 'showFPS' matches delegate 'GTA.KeyPressDelegate'"

 

Any help would be much appreciated, cheers.

 

1: When the BindKey takes a function, the function should have no parameters (like this: public void showFPS() )

2: If you want to draw something, you have to use a PerFrameDrawing.

    		BindKey(Keys.F7, new KeyPressDelegate(showFPS));    		PerFrameDrawing += tehDrawingMaster;        }  		bool drawFPS = false;        public void showFPS()        {        	drawFPS = !drawFPS;        }        public void tehDrawingMaster(object sender, GTA.GraphicsEventArgs e)        {        	if (drawFPS) e.Graphics.DrawText(Game.FPS.ToString(), 20, 20, System.Drawing.Color.Black)        } 

Oh, and, welcome! :D

Edited by LetsPlayOrDy
Link to comment
Share on other sites

Worked great, thanks so much! I was wondering though, is there anyway to slow it down? I mean like is there a way to draw it every X amount of frames? because it moves too fast :(

 

Thanks again bro!

Link to comment
Share on other sites

Worked great, thanks so much! I was wondering though, is there anyway to slow it down? I mean like is there a way to draw it every X amount of frames? because it moves too fast :(

 

Thanks again bro!

How about this?

		GTA.Timer timer;		{				timer = new GTA.Timer(500, false);			timer.Tick += timer_Tick;			timer.Start();			BindKey(Keys.F7, new KeyPressDelegate(showFPS));    		PerFrameDrawing += tehDrawingMaster;        }  		bool drawFPS = false; 		float fps = 0;        public void showFPS()        {        	drawFPS = !drawFPS;        }        public void timer_Tick(object sender, EventArgs e)        {        	fps = Game.FPS;        }        public void tehDrawingMaster(object sender, GTA.GraphicsEventArgs e)        {        	if (drawFPS) e.Graphics.DrawText(fps.ToString(), 20, 20, System.Drawing.Color.Black);        } 
Link to comment
Share on other sites

Post your code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GTA;
using System.Drawing;
using System.Windows.Forms;
namespace ClassLibrary2
{
public class Class1 : Script
{
public Class1()
{
GTA.Timer timer;
timer = new GTA.Timer(500, false);
timer.Tick += timer_Tick;
timer.Start();
BindKey(Keys.F7, new KeyPressDelegate(showFPS));
PerFrameDrawing += tehDrawingMaster;
}
bool drawFPS = false;
float fps = 0;
public void showFPS()
{
drawFPS = !drawFPS;
}
public void timer_Tick(object sender, EventArgs e)
{
fps = Game.FPS;
}
public void tehDrawingMaster(object sender, GraphicsEventArgs e)
{
if (drawFPS) e.Graphics.DrawText(fps.ToString(), 20, 20, System.Drawing.Color.White);
}
}
}
its all just the code you posted. am I missing something?
Link to comment
Share on other sites

Try moving the GTA.Timer timer; in

public class Class1 : Script    {        public Class1()        {            GTA.Timer timer;

to

public class Class1 : Script    {        GTA.Timer timer;        public Class1()        {            

but keep the rest of the timer stuff in the public Class1() method.

Link to comment
Share on other sites

Try moving the GTA.Timer timer; in

public class Class1 : Script    {        public Class1()        {            GTA.Timer timer;

to

public class Class1 : Script    {        GTA.Timer timer;        public Class1()        {            

but keep the rest of the timer stuff in the public Class1() method.

I know the problem, f (drawFPS) e.Graphics.DrawText(fps.ToString(), 20, 20, System.Drawing.Color.White); is using the 'float fps = 0;' not the one in timer_tick.

Edited by TehStranger?
Link to comment
Share on other sites

The 'one in timer_Tick' is float fps = 0;.

float fps = 0; is declaring and setting the initial value, and fps = Game.FPS; is just setting the value, not declaring another variable.

If the problem was the variable (or the timer), then the number 0 would be drawn in the top-left corner of the screen after you press F7.

You said nothing happens, so I'm guessing that means that nothing is being drawn, which means that PerFrameDrawing isn't running

Edited by LetsPlayOrDy
Link to comment
Share on other sites

Yeah you're right, my apologies, I don't know why but it just decided to work now lol :wtf:

 

Thanks for everything bro, you're the best!!!

Link to comment
Share on other sites

Yeah you're right, my apologies, I don't know why but it just decided to work now lol :wtf:

 

Thanks for everything bro, you're the best!!!

Lol well at least it wasn't a coding problem :)

No problem man, any time :D

Link to comment
Share on other sites

Seems solved.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.