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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:53:32+00:00 2026-05-25T14:53:32+00:00

I am attempting to develop a game with canvas element. Right now, I am

  • 0

I am attempting to develop a game with canvas element. Right now, I am drawing tiles (colored squares) as the background, and the hero controlled by arrow keys based off of this demo: http://www.lostdecadegames.com/demos/simple_canvas_game/

However, calling showDungeon() to draw my background makes the movement of the hero not smooth like in the demo. I think the problem is that I am drawing each tile as 32×32, which is making the movement slow in Chrome. Any suggestions or code optimizations I can do? The movement is fine when the tiles are 16×16, but I want the tiles 32×32. I kind of dont want to use CSS to double the size of the canvas as that can ruin the graphics with anti-aliasing. http://www.html5rocks.com/en/tutorials/casestudies/onslaught.html#toc-pixelated

// Draw everything
var render = function() {

   showDungeon();
    ctx.drawImage(img, hero.x, hero.y);

};

// The main game loop
var main = function() {
    var now = Date.now();
    var delta = now - then;

    update(delta / 1000);
    render();

    then = now;
};

// Let's play this game!
var then = Date.now();
setInterval(main, 1); // Execute as fast as possible

unrelated problem: for some reason, I couldnt draw a green square as a hero in render(), so i used an image instead.
http://jsfiddle.net/4M5Xz/4/

  • 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-25T14:53:33+00:00Added an answer on May 25, 2026 at 2:53 pm

    You have a strange loop in the code:

    function showDungeon() {
       for (var x = 0; x < (15*32); x++) {
          for (var y = 0; y < (15*32); y++) {
             ...
          }
       }
    }
    

    It’s like you are drawing the background too many times. I changed it to:

    function showDungeon() {
       for (var x = 0; x < 15; x++) {
          for (var y = 0; y < 15; y++) {
             ...
          }
       }
    }
    

    and it was smooth again.

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

Sidebar

Related Questions

Does attempting to develop some sort of game, even just as a hobby during
I am attempting to develop a service that contains numerous client and server sockets
I've attempting to develop a jQuery accordion, which is work ing pretty well so
I am attempting to learn how to develop on the Android platform but do
I have been attempting to develop an embedded webserver within an application that I
I am part of a new team attempting to develop a new Java software
I am attempting to develop an application that makes use of some simple trig
I am attempting to learn how to develop applications to interact with the Autonomy
The self-extracting executable that I'm attempting to develop is an installer. An end-user will
I'm attempting to build a Virtual Machine to develop a Django application. The OS

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.