Note that there are some explanatory texts on larger screens.

plurals
  1. POExchanging variables between 2 classes
    primarykey
    data
    text
    <p>Whenever I call the method Draw in Sprite, it won't draw it because X, Y, Width and Height are 0. :(</p> <p>code:</p> <pre><code>class Sprite { protected int Y;// { get; set; } protected int X;// { get; set; } { get; set; } protected int Width;// { get; set; } { get; set; } public int Height;// { get; set; } { get; set; } protected Image image;// { get; set; } { get; set; } public Sprite() { } public void Draw(Graphics drawArea) { Image sImage = Image.FromFile("alien.jpg"); drawArea.Clear(Color.White); drawArea.DrawImage(sImage, X, Y, Width, Height); } } class User:Sprite { public User() { } public User(int width, int height, int userWidth, int userHeight) { Sprite sprite = new Sprite(); Image UserImage = Image.FromFile("alien.jpg"); X = width; Y = height; Width = userWidth; Height = userHeight; image = UserImage; } } </code></pre> <p>ps: sprite.Draw is declared in another method in another class, but that all should work just fine. Thanks for helping and probably saving me hours of time :) </p> <p>Nick</p> <p><strong>EDIT</strong></p> <p>here is the subclass which gives the parameter and other stuff.</p> <pre><code> Alien mAlien; User mUser; protected int mLevel; public gameLogic() { } public gameLogic(int width, int height, int level) { mUser = new User(width / 2, height - 30, 30, 30); mAlien = new Alien(width / 2, 5, 30, 30, "alien.jpg", 10 * level); mLevel = level; } public void drawAll(Graphics drawArea) { Sprite sprite = new Sprite(); sprite.Draw(drawArea); } </code></pre> <p>Im sorry for all these errors that'll probably occur, Im a new student :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload