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 6757223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:37:14+00:00 2026-05-26T13:37:14+00:00

I’ve been tinkering with the html5 canvas element for a while now. It is

  • 0

I’ve been tinkering with the html5 canvas element for a while now. It is very useful and all, but I feel very, very limited by the fact that I apparently cannot organize the canvas with objects (not natively).

For instance, if I draw a rectangle, or any other shape, I would really find it useful to be able to access its different properties somewhere else in the script. Instead of that, it seems they just remain, well, drawings, and you have to manually keep track of what is on the canvas, and clear it and rewrite it again when you want to change anything.

My question is: am I missing something ? Is JavaScript providing us with ways to handle objects inside the canvas? If not, are there libraries that do just that already? Which one would you say is the best?

  • 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-05-26T13:37:15+00:00Added an answer on May 26, 2026 at 1:37 pm

    Canvas aren’t really any different from any other drawing-tools. You really do have to keep track of what you’re drawing. The trick is how you do it. It’s a pretty good idea to use objects for it and it’s not that hard. You just need to pass along the context of the canvas to any object, for it to interact with the canvas and draw on it. So if you have an object called Foo you can make the object decide how it wants to be drawn. For instance it could have a method like so:

    function Foo() {
      this.draw = function(context) {
        context.restore();
        context.fillStyle = "rgb(200,0,0)";
        context.fillRect (10, 10, 55, 50);
        context.save();
        // And so on...
      }
    

    In your main drawing loop you could have code similar to this:

    // ... Various init - remember to set the context and store the Foo object somewhere
    foo.draw(context);
    // ...
    

    This would allow you to create objects with their own methods of drawing. There are several ways to do it of course, but the advantage of this one is that it’s pretty modular. If you want you can have several types of objects that inherit from the same generic type with some nifty tools and so on…
    Hope that helps!

    P.S.: I just remembered a brilliant tutorial on the whole HTML 5/canvas stuff: It’s on MDN here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.