cykod / Quintus

HTML5 Game Engine
http://html5quintus.com
GNU General Public License v2.0
1.41k stars 401 forks source link

Bug in Q.UI.Container.fit() and Touch #124

Closed rohitj closed 10 years ago

rohitj commented 10 years ago

I have a container (with Touch component), say Container1, inside another container, say Container2. Container1 has some initial size (h, w). I resize Container1 based on its content (using the fit() method). However, after resizing, touch works on the old size. So, lets say, initially Container1.p.h = Container1.p.w = 100. And later, it is Container1.p.h = Container1.p.w = 50. Then, the touch is still working on the 100x100 area rather than the new 50x50 area.

Below is a sample code:

Q.UI.Container.extend("ClickableContainer", {
    init: function(p) {
        var adjustedP= Q._defaults(p, {
            w: 300,
            h: 100,
            type: Q.SPRITE_PURE_UI,
            collisionMask: Q.SPRITE_NONE,
            fill: "rgba(255, 255, 255, 1)",
            radius: 0,
        });

        this._super(adjustedP);
        this.on("inserted");
        this.add("Touch");
        this.on("touch");
    },

    inserted: function() {
        this.p.label = new Q.UI.Text({label: "Not Clicked"});
        this.insert(this.p.label);
        this.fit(10);
    },

    touch: function() {
        if(this.p.label.p.label == "Clicked")
            this.p.label.p.label = "Not Clicked";
        else
            this.p.label.p.label = "Clicked";
    },
});

Q.scene("test", function(stage) {
    box = stage.insert(new Q.UI.Container({x: 400, y: 300})); // Inserting Container2
    box.insert(new Q.TestContainer({})); // Inserting Container1
});
rohitj commented 10 years ago

Is someone could give me pointers as to what might be wrong, I can look at fixing the bug myself and submit a patch.

ghost commented 10 years ago

@rohitj I'm sorry i haven't had time to dedicate to it the problem is very likely to be inside the fit() method in quintus_ui.js seems it needs to update the touch coordinates when is executed.

rohitj commented 10 years ago

What do you mean by the touch coordinates? I thought that the regular grid was used to decide if the touch occurred on the sprite or not. So, perhaps the grid needs to be updated?

ghost commented 10 years ago

@rohitj it doesn't use a grid, because you can place any sprite in any location so the touch boundaries are always the sprite's boundaries