Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //my first C# example :P
- //http://gtaxscripting.blogspot.com/
- //http://www.facebook.com/GtaIVScripting
- //https://www.youtube.com/user/GTAScripting
- // insert a small png file called anPNG.png into Scripts folder to see the sprite draw method working
- using System;
- using GTA;
- using System.IO;
- using System.Drawing;
- namespace GraphicsExample
- {
- public class GraphicsExample : Script
- {
- private Boolean bDrawTexture = false;
- private Texture myTexture; //an texture can be a png, bmp or jpg file
- public GraphicsExample()
- {
- try
- {
- //try to load the texture from the file
- myTexture = new GTA.Texture(File.ReadAllBytes(".\\scripts\\anPNG.png"));
- //if load is ok set the control variable to true, with this we avoid issues in the draw event
- bDrawTexture = true;
- }
- catch { }
- this.PerFrameDrawing += new GraphicsEventHandler(this.GraphicsEvent);
- }
- private void drawTextWithEffect(GraphicsEventArgs e, string s, Int16 x, Int16 y)
- {
- //draw an rectangle to be the background, the calc to define the X and Wdith its not close to be correct :(, just a example
- e.Graphics.DrawRectangle((Int16)(x + s.Length * 5.7), y + 12, (Int16)s.Length * 12, 25, Color.FromArgb(100, 0, 100, 255));
- //draw the text over the rectangle
- e.Graphics.DrawText(s, x, y, Color.White);
- }
- private void GraphicsEvent(object sender, GraphicsEventArgs e)
- {
- //line
- e.Graphics.DrawLine(10, 10, 100, 10, 3, Color.White);
- //rectangle
- e.Graphics.DrawRectangle(50, 40, 100, 40, Color.DarkBlue);
- //text
- e.Graphics.DrawText("simple text", 10, 60, Color.White);
- //sprite
- if (bDrawTexture) {
- e.Graphics.DrawSprite(myTexture, 100, 300, 100,100,0);
- }
- //text with effect using auxiliar method
- drawTextWithEffect(e, "This was an example", 300, 30);
- drawTextWithEffect(e, "1", 300, 70);
- drawTextWithEffect(e, "This was an example 2 48746541654 456465 asfsa iuyiy", 300, 110);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement