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

  • Home
  • SEARCH
  • 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 8875207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:55:05+00:00 2026-06-14T18:55:05+00:00

I’ve been testing the new typescript with VS 2012 but I have this issue

  • 0

I’ve been testing the new typescript with VS 2012 but I have this issue in my first project:

I have pasted this JS into my ts file but I can’t access the Sprite object is its in the anonymous scope. How can I access it from typescript.

(function () {
  function LoaderProxy() {
    return {
      draw: $.noop,
      fill: $.noop,
      frame: $.noop,
      update: $.noop,
      width: null,
      height: null
    };
  }

  function Sprite(image, sourceX, sourceY, width, height) {
    sourceX = sourceX || 0;
    sourceY = sourceY || 0;
    width = width || image.width;
    height = height || image.height;

    return {
      draw: function(canvas, x, y) {
        canvas.drawImage(
          image,
          sourceX,
          sourceY,
          width,
          height,
          x,
          y,
          width,
          height
        );
      },

      fill: function(canvas, x, y, width, height, repeat) {
        repeat = repeat || "repeat";
        var pattern = canvas.createPattern(image, repeat);
        canvas.fillColor(pattern);
        canvas.fillRect(x, y, width, height);
      },

      width: width,
      height: height
    };
  };

  Sprite.load = function(url, loadedCallback) {
    var img = new Image();
    var proxy = LoaderProxy();

    img.onload = function() {
      var tile = Sprite(this);

      $.extend(proxy, tile);

      if(loadedCallback) {
        loadedCallback(proxy);
      }
    };

    img.src = url;

    return proxy;
  };

  var spriteImagePath = "images/";

  window.Sprite = function(name, callback) {
    return Sprite.load(spriteImagePath + name + ".png", callback);
  };
  window.Sprite.EMPTY = LoaderProxy();
  window.Sprite.load = Sprite.load;
}());

Hope this explains my issue!

Thanks for any assistance

  • 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-14T18:55:07+00:00Added an answer on June 14, 2026 at 6:55 pm

    The first error the compiler gives you is here…

    Sprite.load
    

    It detects that there is no property or function on the Sprite object called load.

    The second error is here…

    var tile = Sprite(this);
    

    The Sprite constructor takes five parameters and you have only passed 1.

    Third up…

    window.Sprite
    

    The Window object doesn’t have a property named Sprite.

    All of the other problems are variations of this issue.

    Here is a suggestion to get things working with minimal changes. The better solution would be to rewrite your Sprite as a class in TypeScript

    var Sprite;
    
    (function () {
      function LoaderProxy() {
        return {
          draw: $.noop,
          fill: $.noop,
          frame: $.noop,
          update: $.noop,
          width: null,
          height: null
        };
      }
    
      Sprite = function (image, sourceX, sourceY, width, height) {
        sourceX = sourceX || 0;
        sourceY = sourceY || 0;
        width = width || image.width;
        height = height || image.height;
    
        return {
          draw: function(canvas, x, y) {
            canvas.drawImage(
              image,
              sourceX,
              sourceY,
              width,
              height,
              x,
              y,
              width,
              height
            );
          },
    
          fill: function(canvas, x, y, width, height, repeat) {
            repeat = repeat || "repeat";
            var pattern = canvas.createPattern(image, repeat);
            canvas.fillColor(pattern);
            canvas.fillRect(x, y, width, height);
          },
    
          width: width,
          height: height
        };
      };
    
      Sprite.load = function(url, loadedCallback) {
        var img = new Image();
        var proxy = LoaderProxy();
    
        img.onload = function() {
          var tile = Sprite(this);
    
          $.extend(proxy, tile);
    
          if(loadedCallback) {
            loadedCallback(proxy);
          }
        };
    
        img.src = url;
    
        return proxy;
      };
    
      var spriteImagePath = "images/";
    
      Sprite = function(name, callback) {
        return Sprite.load(spriteImagePath + name + ".png", callback);
      };
      Sprite.EMPTY = LoaderProxy();
      Sprite.load = Sprite.load;
    }());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been testing my code to save into an XML file locally and
I am new to java and I have been testing my application all day
I have a project the we've been testing using Jira. We just found the
I have been testing out the new WCF fileless activation stuff in .net 4
I have been testing events API against a relatively new account (created June 13,
I have been testing the new deferred AJAX functions in jquery 1.5 and am
I've been testing sending and receiving broadcasts in my application but I have a
I've been doing alot of testing with my new MVC App and now I'm
I'm only new to Unit Testing and ASP.NET MVC. I've been trying to get
I've been testing in Selenium IDE. It's pretty easy to use, and I have

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.