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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:00:14+00:00 2026-05-28T01:00:14+00:00

I am having difficulties rendering several patterns (each with different texture) in the 2d

  • 0

I am having difficulties rendering several patterns (each with different texture) in the 2d context of HTML5 canvas.

Assuming I have three separate canvases, two off-screen containing different textures and one for rendering. Let these offline canvases be A and B.

Then:

var patternA = ctx.createPattern(A, "repeat-x");
ctx.fillStyle = patternA;
ctx.fillRect(100,100,20,20);

var patternB = ctx.createPattern(B, "repeat-y");
ctx.fillStyle = patternB;
ctx.fillRect(150,100,20,20);

There should be two 20×20 rectangles, each with their own pattern, however the second rectangle doesn’t render at all. I’ve tried everything to get them working, but to no avail.

Why is that? How should I render multiple tiling textures onto the same canvas?

  • 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-28T01:00:15+00:00Added an answer on May 28, 2026 at 1:00 am

    What browsers are you trying? With FireFox and Chrome, I couldn’t get either pattern to render with repeat-x or repeat-y. Instead, I was able to get both to render with just repeat. (See http://jsfiddle.net/ZthsS/1/)

    It is possible that browsers have an incomplete implementation of the specification. According to the implementation status at http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-createpattern, IE beta and FF nightly pass all test cases but other browsers don’t. I would recommend just using repeat for the time being. You could emulate repeat-x and repeat-y by simply limiting the width of the fillRect to the width of the pattern:

    var patternA = ctx.createPattern(A, "repeat");
    ctx.fillStyle = patternA;
    ctx.fillRect(100,100,20,Math.min(20, A.height));
    
    var patternB = ctx.createPattern(B, "repeat");
    ctx.fillStyle = patternB;
    ctx.fillRect(150,100,Math.min(20, B.width), 20);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm having difficulties implementing custom widget rendering in a QListView . I currently have
I am having difficulties how to construct my question, but if I have to
I'm having difficulties adding momentum to my spinning wheel. I have this wheel (something
I'm having difficulties working with some legacy enums that have multiple zero values. Whenever
I'm having difficulties reading an app.config using the ConfigurationManager. I have a custom section,
I'm having difficulties seeing why one way works and way doesn't. I have; switch
I am having difficulties scaling the size of an image on an HTML canvas
I am having difficulties with the different clocks which can be accessed by clock_gettime
Having difficulties with ie7 bug involving absolute positioning. Have tried a few solutions without
I have been having difficulties with a piece of script I am creating, and

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.