có pro nào giúp mình với
mình đang làm đồ án cuối kì môn lập trinh win bằng xna nhưng mà đụng tới kế thừa là bị lỗi!!!
mình có lớp Rung kế thừa lớp Tile
Lớp Tile
Lớp rung:
Trong Game1.cs:
thì lại bị lỗi như vây:
Untitled.png
còn có 2 lớp Gach và Đá ko kế thừa lớp Tile thì Draw bình thương
2.png
bị lỗi này chỉ khi xài tới list<> còn nếu bình thường Draw 1 Rung thì vẫn bình thường !!!
mong các Bro xem giúp!
mình đang làm đồ án cuối kì môn lập trinh win bằng xna nhưng mà đụng tới kế thừa là bị lỗi!!!
mình có lớp Rung kế thừa lớp Tile
Lớp Tile
Code:
using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; namespace tank { class Tile { Texture2D texture{get;set;} Vector2 toado; public bool isCollides = false; public Tile(Game game, Vector2 _pos) { toado = _pos; } public void LoadContent(ContentManager Content,String str) { texture = Content.Load<Texture2D>(str); } public Rectangle GetBound() { return new Rectangle((int)toado.X, (int)toado.Y, texture.Width, texture.Height); } public bool CheckCollides(xetank sp) { return sp.GetBound().Intersects(GetBound()); } public void Draw(SpriteBatch sp) { sp.Draw(texture, toado, Color.White); } } }
Code:
using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; namespace tank { class Rung:Tile { public Rung(Game game, Vector2 pos) : base(game, pos) { } } }
Code:
//ve khu rung foreach (Rung khurung in listRung) khurung.Draw(spriteBatch);
Untitled.png
còn có 2 lớp Gach và Đá ko kế thừa lớp Tile thì Draw bình thương
Code:
//ve gach foreach (Gach viengach in listgach) viengach.Draw(spriteBatch); //ve da foreach (Da vienda in listDa) vienda.Draw(spriteBatch);
bị lỗi này chỉ khi xài tới list<> còn nếu bình thường Draw 1 Rung thì vẫn bình thường !!!
mong các Bro xem giúp!
Comment