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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:03:07+00:00 2026-06-14T10:03:07+00:00

I am quite new to using HTML5 Canvas and KineticJS so please forgive me

  • 0

I am quite new to using HTML5 Canvas and KineticJS so please forgive me if this is an obvious error on my part.

My issue is that I am using a Group made up of Shapes. The Shapes use a drawFunc which does the drawing magic. All good stuff. However – I notice that the settings made in my Shape call seem to override the “global” context settings. This is best shown by a fiddle I created that adds some crosses (Shapes) to the standard “KineticJS drag and drop a group” demo.

  // ----------------------------------------------------------[ my bit starts ]
        var tmp_x = i * 30 + 100
        var tmp_y = i * 30 + 40
        var shape = new Kinetic.Shape({

            drawFunc: function(context) {

                context.moveTo(tmp_x-10, tmp_y);
                context.lineTo(tmp_x + 10, tmp_y);
                context.moveTo(tmp_x, tmp_y - 10);
                context.lineTo(tmp_x, tmp_y + 10);

                this.fill(context);
                this.stroke(context);
            } ,
            fill: "#0FD2FF",
            stroke: "orange"
        });
        group.add(shape);
        // ----------------------------------------------------------[ my bit ends ]

        var box = new Kinetic.Rect({
            x: i * 30 + 210,
            y: i * 18 + 40,
            width: 100,
            height: 50,
            name: colors[i],
            fill: colors[i],
            stroke: 'black',
            strokeWidth: 4
        });

        group.add(box);

You will notice that the stroke and fill settings made in the Shape stamp on the settings for the coloured boxes – apart from the last one which is created AFTER the last cross (Shape).

It feels like some sort of late evaluation thing because things are only done when the Group gets rendered.

Could someone give me a clue as to what I am doing wrong?

  • 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-14T10:03:09+00:00Added an answer on June 14, 2026 at 10:03 am

    Context is global, so when you apply settings to it, they will persist for every shape that uses the context to draw.

    You need to call context.beginPath() and context.closePath() in your drawFunc, around your other calls to context, to indicate that this is a new and separate shape from the others.

    So now, your code for shape would be like this:

    var shape = new Kinetic.Shape({
        drawFunc: function(context) {
            context.beginPath();
            context.moveTo(tmp_x-10, tmp_y);
            context.lineTo(tmp_x + 10, tmp_y);
            context.moveTo(tmp_x, tmp_y - 10);
            context.lineTo(tmp_x, tmp_y + 10);
            context.closePath();
    
            this.fill(context);
            this.stroke(context);
        },
        fill: "#0FD2FF",
        stroke: "orange"
    });
    

    This will prevent your context settings from leaking to other shapes.

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

Sidebar

Related Questions

I am using treegrid with jqGrid and am quite new to this plugin. I
This is my first time using this site and I am quite new to
I'm new to web design, so please forgive if this is super simple- I've
So I came across this new tag in HTML5, <keygen> . I can't quite
I'm quite new to using php so im not sure if this is possible
Bear with me, as I'm quite new to using regular expressions. I have regexp
I'm quite new to PL/SQL, and am using Oracle SQL Developer to write a
I am quite new to Selenium. Currently i am using selenium driver for writing
I'm quite new to RoR. Sorry if I'm using wrong terminology or the answer
I'm building a web application using Yii framework, and i'm quite new to it.

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.