לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 20-08-2006, 08:01
  ben chen ben chen אינו מחובר  
 
חבר מתאריך: 14.11.05
הודעות: 56
עשיית אנימציה חלקה ב C#.

CS2DGL - C Sharp 2D Graphics Laibrary
טוב אז ככה זוהי ספרייה גרפית- למי שלא יודע ספרייה גרפית זוהי ספרייה שמאפשרת לך לעשות כל מיני פעולות גרפיות. אז ככה הספרייה הזאת פועלת על C# והיא לא בדיוק כמו המקצועיות..אז ככה היא יכולה להשים רקעים, לעשות אנימציה של תמונות הטייפ המומלץ הוא png מהסיבה שהוא מאפשר גם צפייה בשקוף באנימצייה... טוב אז ככה אם מישהו נגיד מתכנת בויזואל בייסיק או אחד מאלה יוכל להתאים תסיפרייה לשאר שפות התכנות של Microsoft Visual Studio אשמח מאוד. וכן בבקשה תעשו בזה כל מיני שטויות ותגידו לי דברים לשפר.. טוב הכל רשות למטה ד"א זה נבנה בגירסא Net 2003 אז יש סיכוי שתצטרכו התאמה קלה אם שלכם גירסא ישנה יותר..
אני מדגיש זה אך ורק ל Visual C#!!!

מטרות השימוש:
כדי לבנות תוכנות עם גרפיקת תמונות.
כדי לבנות משחקים.

התקנת הספריה:
העתיקו את הקוד של הספריה והדביקו אותו אחרי הקלאס הראשי.

קוד:
#region Graphic Laibrary public class ImagesAnimation : System.Windows.Forms.Form { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public ImagesAnimation(int animationDelay) { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // animationTimer.Tick += new EventHandler(Animation); animationTimer.Interval = animationDelay; } public ImagesAnimation() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // animationTimer.Tick += new EventHandler(Animation); animationTimer.Interval = 300; } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { // // Images Animation // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.WindowState = FormWindowState.Maximized; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "ImagesAnimation"; this.ShowInTaskbar = false; this.TransparencyKey = System.Drawing.SystemColors.Control; this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; } #endregion Hashtable imagesHashtable = new Hashtable(); Point notInScreenPoint = new Point(3000,3000); Point animationPoint = new Point(0,0); int AddX = 5; int AddY = 0; Timer animationTimer = new Timer(); int animationIndex = 0; int loops; int currentLoop = 0; int animationLastIndex; string[] animationKeys; Graphics myGrfx; public int AnimationDelay { get { return animationTimer.Interval; } set { animationTimer.Interval = value; } } private void Animation(object obj, EventArgs e) { animationTimer.Stop(); animationPoint.X += AddX; animationPoint.Y += AddY; ImageForm thisImageForm = imagesHashtable[animationKeys[animationIndex]] as ImageForm; thisImageForm.Location = animationPoint; thisImageForm.Visible = true; if ((currentLoop != 0)||(animationIndex != 0)) { ImageForm lastImageForm = imagesHashtable[animationKeys[animationLastIndex]] as ImageForm; lastImageForm.Visible = false; } animationLastIndex = animationIndex; if (animationIndex == animationKeys.Length - 1) { if (currentLoop == loops) return; animationIndex = 0; currentLoop ++; } else animationIndex ++; animationTimer.Start(); } public void ClearBG(Color bgColor) { myGrfx = CreateGraphics(); myGrfx.Clear(bgColor); } public void AddBG(Image backgroundImage,int width,int height) { myGrfx.DrawImage(backgroundImage,0,0,width,height) ; } public bool LoadImages(string[] imagesPath, string[] imagesKeys) { if (imagesPath.Length != imagesKeys.Length) return false; for (int i = 0;i < imagesPath.Length;i ++) { ImageForm imageForm = new ImageForm(Image.FromFile(imagesPath[i])); imagesHashtable.Add(imagesKeys[i],imageForm); } return true; } public void ClearImages(string[] imagesToClear) { for (int i = 0; i < imagesToClear.Length; i++) { ImageForm imageForm = imagesHashtable[imagesToClear[i]] as ImageForm; imageForm.Visible = false; } } public void ShowForms(string[] formsKeys) { for (int i = 0;i < formsKeys.Length;i ++) { ImageForm imageForm = imagesHashtable[formsKeys[i]] as ImageForm; imageForm.Location = animationPoint; imageForm.Visible = false; imageForm.Show(); } } public void Animate(string[] formsKeys,int addX,int addY,Point animationStartPosition,int animationLoops) { //Initialize Vars loops = animationLoops; AddX = addX; AddY = addY; animationPoint.X = animationStartPosition.X; animationPoint.Y = animationStartPosition.Y; ClearImages(formsKeys); animationKeys = formsKeys; animationPoint.X -= AddX; animationPoint.Y -= AddY; // Start Animation animationTimer.Start(); } } public class ImageForm : System.Windows.Forms.Form { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; Image imageToDrawGlobal; public ImageForm(Image imageToDraw) { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // this.Size = imageToDraw.Size; imageToDrawGlobal = imageToDraw; } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { // // ImageForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "ImageForm"; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.TransparencyKey = System.Drawing.SystemColors.Control; this.Closed += new System.EventHandler(this.ImageForm_Closed); this.Paint += new System.Windows.Forms.PaintEventHandler(this.ImageF orm_Paint); } #endregion private void ImageForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics myGrfx = CreateGraphics(); myGrfx.DrawImage(imageToDrawGlobal,0,0); } private void ImageForm_Closed(object sender, System.EventArgs e) { Application.Exit(); } } public class KeysForm : System.Windows.Forms.Form { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public KeysForm() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { // // KeysForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Name = "KeysForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n; this.Text = "KeysForm"; this.TopMost = true; this.TransparencyKey = System.Drawing.SystemColors.Control; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.Closing += new System.ComponentModel.CancelEventHandler(this.Keys Form_Closing); this.ShowInTaskbar = false; this.FormBorderStyle = FormBorderStyle.None; } #endregion private void KeysForm_Closing(object sender, System.ComponentModel.CancelEventArgs e) { Application.Exit(); } } #endregion


הגדרת הספריה:
קוד:
ImagesAnimation imageAnimation = new ImagesAnimation();

יש אפשרות לשלוח גם את הדיליי של האנימציה(החלפה בן תמונה לתמונה) בms.
אם לא שולחים דיליי אז ברירת המחדל היא 100ms = 0.1s.
כמובן שאחרי ההגדרה של הספרייה תמיד אפשר להגדיר את זה אחר כך על ידי כך.
קוד:
imageAnimation.AnimationDelay = X;


הפעלת הספריה:
Show - הצגת בפעם הראשונה(קיים בכל קלאס). חובה!
LoadImages - לטעון תמונות. חובה לפני כל דבר אחר חוץ מ Show.
ShowForms - מפעיל את הפונקצייה Show במערכת הפורמים שבהם התמונות נמצאות. חובה לפני אנימציה.
ClearBG - מנקה את הרקע של הספרייה לצבע חלק(מוחק גם רקע תמונה). לא חובה.
AddBG - מוסיף תמונה לרקע.לא חובה.
Animate - עושה את האנימציה.לא חובה.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 17:39

הדף נוצר ב 0.05 שניות עם 12 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר