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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:07:21+00:00 2026-06-16T19:07:21+00:00

Hi I have two shapes that are overlapping (implementation in KineticJs). I want to

  • 0

Hi I have two shapes that are overlapping (implementation in KineticJs). I want to change the color of these shapes if the mouse hovers above them. In case the mouse hovers above the overlapped(intersection) area, I want both the shapes to change color. However only the top most shape is changing color.

Example at http://jsfiddle.net/sandeepy02/NST8C/ where I want the colour of both rect to be black if I hover mouse over the pverlapped area.

stage = new Kinetic.Stage({
    container: "container",
    width: 320,
    height: 320
});
layer = new Kinetic.Layer();
elemOne = new Kinetic.Rect({
    x: 100,
    y: 100,
    width: 100,
    height: 100,
    fill: 'red',
    stroke: 'black',
    strokeWidth: 0,
    draggable: false
});
elemOne.on('mousemove', function() {
    this.setFill("black");
    this.setZIndex(10);
    layer.draw();
});
elemOne.on('mouseout', function() {
    this.setFill("red");
    this.setZIndex(1);
            layer.draw();
});
elemTwo = new Kinetic.Rect({
    x: 150,
    y: 150,
    width: 100,
    height: 100,
    fill: 'green',
    stroke: 'black',
    strokeWidth: 0,
    draggable: false
});
elemTwo.on('mousemove', function() {
    this.setFill("black");
    this.setZIndex(10);
            layer.draw();
});
elemTwo.on('mouseout', function() {
    this.setFill("green");
    this.setZIndex(1);
             layer.draw();
});
layer.add(elemOne);
layer.add(elemTwo);
stage.add(layer);
  • 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-16T19:07:22+00:00Added an answer on June 16, 2026 at 7:07 pm

    Kinda solved it by creating a background element and observing mouseposition for each move. In each mousemove, I calculate if the mouse position is within every element. If yes, then change color.
    Demo:
    http://jsfiddle.net/sandeepy02/NST8C/5/

    Source:

    stage = new Kinetic.Stage({
        container: "container",
        width: 500,
        height: 500
    });
    background = new Kinetic.Rect({
        x: 0,
        y: 0,
        width: 500,
        height: 500,
        fill: 'white',
        stroke: 'white',
        strokeWidth: 0,
        draggable: false,
    });
    layer = new Kinetic.Layer();
    elemOne = new Kinetic.Rect({
        x: 100,
        y: 100,
        width: 100,
        height: 100,
        fill: 'red',
        stroke: 'black',
        strokeWidth: 0,
        draggable: false,
        name: 'elem',
        id: 1,
        col: 'red'
    });
    
    elemTwo = new Kinetic.Rect({
        x: 150,
        y: 150,
        width: 100,
        height: 100,
        fill: 'green',
        stroke: 'black',
        strokeWidth: 0,
        draggable: false,
        name: 'elem',
        id: 2,
        col: 'green'
    });
    
    stage.on('mousemove', function() {
        //alert("a");
        var mousePos = stage.getMousePosition();
        var shapes = stage.get('.elem');
        var i;
        for (i = 0; i < shapes.length; i++) {
            if (shapes[i].intersects(mousePos.x, mousePos.y)) {
                shapes[i].setFill("black");
            }
            else {
                if (shapes[i].getId() == 1) {
                    shapes[i].setFill("red");
                }
                else shapes[i].setFill("green");
            }
        }
        layer.draw();
    });
    layer.add(background);
    layer.add(elemOne);
    layer.add(elemTwo);
    stage.add(layer);
    

    Obviously I am not proud of its performance as for each mousemove I am checking each element. Performance should not be an issue if I were to check for mousedown or click, but I think someone out there in this wide world can provide a better solution?

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

Sidebar

Related Questions

I have two shapes which are cross sections of a channel. I want to
I have two overlapping shapes in my C# app, defined by Point arrays. I
I have a program that allows you to move various Shapes about. I want
Problem: I have two overlapping 2D shapes, A and B, each shape having the
let's say I have two shapes wrapped in Movieclip container. How can I detect
I have an image map with two different area shape attributes. I want to
If I have two objects in chipmunk (I'm using cocos2d-iphone), once I've detected that
I have, as an example, the following two images: http://img571.imageshack.us/i/spain.jpg/ http://img97.imageshack.us/i/spainoverlay.png/ I want to
I have made two classes in a SVG-file to decide the fill color of
I have two numpy arrays of different shapes, but with the same length (leading

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.