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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:23:38+00:00 2026-06-06T11:23:38+00:00

I am making a game engine using HTML5 canvas, and I have decided to

  • 0

I am making a game engine using HTML5 canvas, and I have decided to write some “wrappers” for images, because that gives me a common interface for various types of animation, images, etc. What I mean is that every object just has a .picture property which provides things such as a draw() method, .phi value for rotation, an .alpha, etc. What is cool about this approach to me is that, essentially, this .picture property can be anything:

  • An image (a wrapper called Picture actually).
  • An animation (a wrapper for many images with some functiones such as next() and getImage()).
  • A composition (many images and animations that get drawn on top of eachother or something else that has a draw method.)
  • A state (similar to composition)

For convinience, all these wrappers (image, animation, composition, state) translate and rotate the context (you can’t successfully rotate an HTML5 canvas context without translating it to the point of rotation first). Now, that’s a lot of translations! First issue: is translating the context for every draw call expensive?

Another issue is that this design implies a lot of function calls!

Here’s how the process goes:

  • The renderer iterates through a scene, and then the scene’s layers
  • When it gets to a drawable (ob.picture != undefined), it calls it’s .picture‘s draw function (every visible object inherits from a “class” called Drawable, that class actually has the position and picture properties)

Here is what happens in the best-case scenario:

  • The drawable’s .picture property is a Picture object (wrapper for images)
  • The .picture translates the context to it’s position
  • The .picture rotates the context
  • The .picture calls context.drawImage(.picture.image, etc);

This is what happens in the worst-case scenario:

  • The picture property is a Composition or a State object
  • The composition starts iterating through it’s elements, each of which is another Picture or Animation (or, even worse, another Composition/State)
  • Calls their draw methods
  • They render the actual picture/iterate through their elements and this repeats

As you see, there are a lot of draw function calls. Will this be a significant speed problem, or is calling functions inexpensive?

EDIT: This question has changed a bit. The “game” became an “engine”, and the engine’s structure is altered a slight bit. But, nothing too essential or different.

  • 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-06T11:23:39+00:00Added an answer on June 6, 2026 at 11:23 am

    Not sure about the context translation, but I assume translations are not free.

    For the function calls, it depends on the amount of objects you’re drawing. A function call has a non-zero runtime length. It is very small though.

    I set up a real dumb and simple example below measuring the runtime of a bunch of nested functions: http://jsfiddle.net/luketmillar/D5sHE/

    When it comes to graphics every millisecond counts. If you can avoid extra function calls, might as well.

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

Sidebar

Related Questions

I am making an HTML5 game engine. There is only one file that is
I'm making some game, and I have made it pretty much all, but not
I'm making a game which is using sound and images. The weirdest thing is
Context I'm making a game engine using SDL and OpenGL. I'm trying to find
okay i'm making a game using c++ (for the engine) and openGL, now i've
I want to try making a simple game engine. Just something that handles states,
I've been making a game using the rokonandroid game engine, but I randomly get
I'm making a 3D game in XNA using Ox Engine. There is very little
I'm making a iPhone App written in Objective-C using the Cocos2d game engine. I'm
Making a game using Blender for 3D models and Unity for the game engine.

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.