2013-03-05 7 views
6

मान्यता प्राप्त नहीं http://xbox.create.msdn.com/en-US/education/tutorial/2dgame/creating_the_player से, यह निर्देश दिया जाता है कि इस कोड का इस्तेमाल किया जा:सी # 'प्राप्त' एक्सेसर

public int Width() 
    { 
     get { return PlayerTexture.Width; } 
    } 

    public int Height() 
    { 
     get { return PlayerTexture.Height; } 
    } 

हालांकि, 'हो' एक्सेसर बिल्कुल मान्यता प्राप्त होना प्रकट नहीं होता है। मुझे निम्न त्रुटियां मिलती हैं:

  • नाम 'प्राप्त' वर्तमान संदर्भ में मौजूद नहीं है।

  • केवल असाइनमेंट, कॉल, वृद्धि, कमी, और नए ऑब्जेक्ट एक्सप्रेशन को कथन के रूप में उपयोग किया जा सकता है।

क्या मुझे 'सिस्टम का उपयोग करना' (कुछ) 'लाइन याद आ रही है? मैंने देखा है कि यह मेरी समस्या की जांच करते समय सफलतापूर्वक अनगिनत बार उपयोग किया जाता है लेकिन मुझे कोई भी व्यक्ति नहीं मिल रहा है जो एक ही चीज़ में चला गया है।

मैं माइक्रोसॉफ्ट विजुअल सी # 2010 एक्सप्रेस के साथ एक्सएनए गेम स्टूडियो 4.0 का उपयोग कर रहा हूं। कि लगता है कि आप की घोषणा करने के प्रयास कर रहे हैं -

public int Width() 
{ 
    get { return PlayerTexture.Width; } 
} 

() हिस्सा गलत है:

using System; 
using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Graphics; 

namespace Shooter 
{ 
class Player 
{ 
    private Texture2D PlayerTexture; 
    public Vector2 Position; 
    public bool Active; 
    public int Health; 

    public int Width() 
    { 
     get { return PlayerTexture.Width; } 
    } 

    public int Height() 
    { 
     get { return PlayerTexture.Height; } 
    } 

    public void Initialise(Texture2D texture, Vector2 position) 
    { 
     PlayerTexture = texture; 
     Position = position; 
     Active = true; 
     Health = 100; 
    } 

    public void Update() 
    { 
    } 

    public void Draw(SpriteBatch spriteBatch) 
    { 
     spriteBatch.Draw(PlayerTexture, Position, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); 
    } 
} 
} 

उत्तर

13

यह एक वैध संपत्ति घोषणा नहीं है: यह Player.cs वर्ग के लिए अपना पूरा कोड है एक संपत्ति के बजाय एक विधि। आप होना चाहिए:

public int Width 
{ 
    get { return PlayerTexture.Width; } 
} 

(। मैं बाकी की जाँच नहीं की है, लेकिन है कि अच्छी तरह से सभी यह गलत है हो सकता है)

+0

जॉन, मुझे उस जवाब की गति का भय है! – Sam

+0

वाह, पूरी तरह से काम किया। धन्यवाद एक टन, आदमी! जितनी जल्दी हो सके उत्तर स्वीकार करेंगे। – user2134261

+0

हाँ, जितना तेज़ मैं टाइप कर सकता हूं, एलओएल –

0

आप () दूर करने के लिए होगा, () इसकी एक विधि, नहीं इंगित करता है एक संपत्ति

विधि:

public int Width() 
{ 
    return PlayerTexture.Width; 
} 

संपत्ति:

public int Width 
{ 
    get { return PlayerTexture.Width; } 
} 
संबंधित मुद्दे