Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9110557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:17:53+00:00 2026-06-17T03:17:53+00:00

Whenever I call the method Draw in Sprite, it won’t draw it because X,

  • 0

Whenever I call the method Draw in Sprite, it won’t draw it because X, Y, Width and Height are 0. 🙁

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;
    }
}

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 🙂

Nick

EDIT

here is the subclass which gives the parameter and other stuff.

  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);
}

Im sorry for all these errors that’ll probably occur, Im a new student 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:17:54+00:00Added an answer on June 17, 2026 at 3:17 am

    Try this:

    public User(int width, int height, int userWidth, int userHeight)
    {
        Sprite sprite = new Sprite();
        Image UserImage = Image.FromFile("alien.jpg");
    
        sprite.X = width;
        sprite.Y = height;
        sprite.Width = userWidth;  
        sprite.Height = userHeight;
        sprite.image = UserImage;
    }
    

    In order to access the fields of the sprite, you have to specify which Sprite object you are modifying. This is done by writing the name of the variable followed by .

    EDIT: Just realized that there is another problem – your User class is inheriting from the Sprite class. Apparently your users are sprites, according to the comments, so you’ll want to never instantiate a Sprite, and just use the User class instead:

    class User:Sprite
    {
        public User(int width, int height, int userWidth, int userHeight)
        {
            Image UserImage = Image.FromFile("alien.jpg");
    
            X = width;
            Y = height;
            Width = userWidth;  
            Height = userHeight;
            image = UserImage;
        }
    }
    

    Then instead of calling draw on a sprite in the other file, use the following:

    User user = new User(x, y, width, height)
    
    ...
    
    user.draw();
    

    The key here is to make sure you are using new User... and not new Sprite – even if you are assigning to a Sprite variable e.g. Sprite s = new User(...);.

    Then just make sure you call draw on the same object – the user.draw line. If you want to check that you’re doing it right, try making Sprite abstract – abstract class Sprite – that way there will be compile errors if you try to instantiate Sprite instead of User.

    EDIT 2: Ok, all you really need to do is change your calling code:

    public void drawAll(Graphics drawArea)
    {
        mUser.draw(drawArea);
        mAlien.draw(drawArea);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whenever I call my logger in a method, e.g. _logger.Debug(Connecting to database...); I get
Whenever I call the below method (CoffeeScript) that is on the server I get
I'm working on a Perl module and whenever I call the skip() method I
I'm using the facebook graph PHP sdk - whenever I call the $facebook->api method
I keep getting this error whenever I call gethostbyname() in my C code. ==7983==
I have two Activities along with one Application class, and whenever I call my
whenever I try to call my ejb from a client, I get this error
I'm using the facebook graph PHP sdk - whenever I call the $facebook->api method
Whenever i override a method of a base class, other than my implementation of
Microsoft.TeamFoundation.VersionControl.Client.Workspace.PendAdd For some reason, whenever I call the PendAdd method from the TFS API,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.