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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:48:55+00:00 2026-06-18T05:48:55+00:00

The situation : I’m creating a game where every player has its snake. The

  • 0

The situation: I’m creating a game where every player has its snake.

The problem: Under special circumstances, a players snake could be of more than thousand arcs. I redraw the canvas on every tick (I try to get 60fps). Now, because there are too much arcs to draw, it gets very slow.

My idea: Draw the snake of every player to an image/texture, and only redraw the whole image for each player on the canvas.

My question: Is this possible? When yes, what do I have to search for? I’m not that experienced in game development.

  • 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-18T05:48:56+00:00Added an answer on June 18, 2026 at 5:48 am

    I’d suggest looking into the context.createPattern method. You can dynamically create a new canvas and draw your complex image on it. After you’re done drawing once, you can call context.createPattern(dynamicCanvas, 'no-repeat') and then keep a reference to that pattern around. Then anytime you want to draw that snake, translate your context to the appropriate location and set the context.fillStyle to be your pattern and fill in a rectangle that fits your pattern. Here’s some generalized code:

    // Only do this once per unique snake, not per frame
    var patternCanvas = document.createElement("canvas");
    // Set the size to be the minimum size to draw your snake on
    patternCanvas.width = 100;
    patternCanvas.height = 100;
    // code that draws snake onto patternCanvas here
    // ...
    
    // Create the pattern
    var pattern = patternCanvas.getContext("2d").createPattern(patternCanvas, "no-repeat");
    
    // Using your real canvas that's drawing every frame
    var realContext = realCanvas.getContext("2d");
    realContext.save();
    realContext.translate(50, 80); // x, y coordinates of where you want to draw your snake
    realContext.fillStyle = pattern;
    realContext.fillRect(0, 0, 100, 100); // The last two parameters are your width and height of your snake pattern
    realContext.restore();
    

    Notice that createPattern can take an entire canvas object and you never need to append the patternCanvas to a DOM object, so it acts like a back-buffer.

    When drawing your patterns, try to draw them all within the same save/restore. Just keep translating and filling rectangles. Each save/restore and modification to the context will slow you down, so you want to make sure you are batching calls as much as possible.

    There can be any number of reasons for why Canvas may be drawing slow, so I’d recommend following some of the ideas mentioned at http://www.html5rocks.com/en/tutorials/canvas/performance/.

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

Sidebar

Related Questions

Situation: need to find which layer the user has touched. Problem: Apple says we
Situation now: 4 navigation links, click on it opens contentfield with animation. Problem: it
Situation : An upper class dialog generates a raster with squares. A player sits
Situation: I have been creating webpages in HTML5/CSS3 & Javascript using Sublime 2 text
Situation I'm creating a C#/WPF 4 application using a SQL Compact Edition database as
Situation: Hello! I have a little problem in a C# project. I am using
Situation: I am creating an app in C# that uses Oracle.DataAccess.Client (11g) to do
Situation I've been creating a program to exchange messages between two computers in the
Situation: I'm creating a minimal client for creating user reports. The main form features
Situation: WPF application, .NET4, DataSource (MS SQL Server 2008) created with the designer Problem:

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.