اذهب إلى المحتوى
  • 0

كيف أضبط مقاس النافذة عند إعادة الإظهار باستخدام #ّّC؟

K@m@l

السؤال

لدي تطبيق سطح مكتب على لغة #C، والمشكل الذي أواجه أن مقاس النافذة لا يبقى على حاله عند تصغيره بعد إخفاء النافذة وإظهارها من جديد، ولا أدري ما الذي يحدث بالضبط؟

إليكم لمحة حول الكود البرمجي المستعمل في التطبيق:

طريقة Draw :

public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
{
    // تموضع المكونات 
    spriteBatch.Draw(textureImage, position, new Rectangle(
    (currentFrame.X * frameSize.X),
    (currentFrame.Y * frameSize.Y),
    frameSize.X, frameSize.Y),
    Color.White, 0, Vector2.Zero, 2, SpriteEffects.None, 0);
}

حساب مسافات الموقع:

//  للتموضع Vector2 استعمال

public PlayerMovement(Texture2D textureImage, Vector2 position, Point frameSize, int collisionOffSet, Point currentFrame, Point startFrame, Point sheetSize, float speed, float speedMultiplier, float millisecondsPerFrame)
        : base(textureImage, position, frameSize, collisionOffSet, currentFrame, startFrame, sheetSize, speed, speedMultiplier, millisecondsPerFrame)
{
        children = new List<Sprite>();
}

فكيف يمكنني المحافظة على مقاس النافذة وأماكن مكوناتها حتى بعد إخفاءها وإظهارها من جديد؟

رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

من خلال تجربتي في التعامل مع تطبيقات سطح المكتب بـ #C، أريد القول بأن استعمال:

Game.Window.ClientBounds

قد يعرضك لبعض المشاكل عند الإنقاص  من مقاس النافذة، لذا أقدم لك هذه الشفرة من تطبيق سابق لي:

Rectangle gdm = Game.Window.ClientBounds;
if (DrawLocation.X < 0) DrawLocation = new Vector2(0, DrawLocation.Y);
if (DrawLocation.Y < 0) DrawLocation = new Vector2(DrawLocation.X, 0);
if (DrawLocation.X > gdm.Width - DrawAreaWithOffset.Width) DrawLocation = new Vector2(gdm.Width - DrawAreaWithOffset.Width, DrawLocation.Y);
if (DrawLocation.Y > gdm.Height - DrawAreaWithOffset.Height) DrawLocation = new Vector2(DrawLocation.X, gdm.Height - DrawAreaWithOffset.Height);

أيضا  ستتفادى مشاكل الواجهة عن طريق تعيين width و hieght 'الطول والعرض':

Rectangle gdm = Game.Window.ClientBounds;
if (gdm.Width > 0 && gdm.Height > 0) //protect when window is minimized
{
    if (DrawLocation.X < 0)
        DrawLocation = new Vector2(0, DrawLocation.Y);
    if (DrawLocation.Y < 0)
        DrawLocation = new Vector2(DrawLocation.X, 0);
    if (DrawLocation.X > gdm.Width - DrawAreaWithOffset.Width)
        DrawLocation = new Vector2(gdm.Width - DrawAreaWithOffset.Width, DrawLocation.Y);
    if (DrawLocation.Y > gdm.Height - DrawAreaWithOffset.Height)
        DrawLocation = new Vector2(DrawLocation.X, gdm.Height - DrawAreaWithOffset.Height);
}

وكمرجع يمكنك رؤية  الرابط.

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...