Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

me.ImageLayer.achorPoint should map to the viewport boundary #632

Closed
parasyte opened this issue Jan 11, 2015 · 5 comments
Closed

me.ImageLayer.achorPoint should map to the viewport boundary #632

parasyte opened this issue Jan 11, 2015 · 5 comments
Labels
Milestone

Comments

@parasyte
Copy link
Collaborator

See also: #604 #332

The anchorPoint setting is unintuitive, as currently implemented. It maps the ImageLayer to the visible part of the viewport. And secondly, the ImageLayer position alters the source coordinates instead of the destination coordinates. Combined, these issues make it very difficult to accurately position an ImageLayer with absolute coordinates, or coordinates relative to the map.

Here are some (really long) threads that also go over this topic, including a lot of workarounds for it:

For the most part, the workarounds allow things to work as expected. But this is clearly a difficult bug to deal with.

To provide a better technical description, the anchorPoint should map an ImageLayer to the viewport boundary, taking into account the ImageLayer size and the viewport boundary size. This mapping establishes the ImageLayer's origin. Then, as the viewport moves, the ImageLayer moves at a ratio proportional to the viewport position in relation to the viewport boundary. It is not easy to digest in writing, but in practice this will solve almost all of the issues around positioning an ImageLayer with an active ratio.

@parasyte parasyte added the Bug label Jan 11, 2015
@parasyte parasyte added this to the 2.2.0 milestone Jan 11, 2015
@xorinzor
Copy link
Contributor

This code allowed me to set the x/y coordinates of the ImageLayer properly

me.CustomImageLayer = me.ImageLayer.extend({
    init: function(x, y, name, width, height, image, z, ratio) {

        this._super(me.ImageLayer, "init", [name, width, height, image, z, ratio]);

        //added the this.pos.<x/y> to prevent "jumping" of the imagelayer when moving the viewport around
        this.pos.x = this.x = x;
        this.pos.y = this.y = y;
    },

    updateLayer : function (vpos) {
        this._super(me.ImageLayer, "updateLayer", [ vpos ]);

        //I couldn't get any modifications on the Y-axis to work so I left this static
        this.pos.y = vpos.y - this.y;

        if(this.repeatX) {
            this.pos.x += (((vpos.x - this.lastpos.x) - this.x) * this.ratio.x) % this.imagewidth;
            this.pos.x = (this.imagewidth + this.pos.x) % this.imagewidth;
        } else {
            this.pos.x = vpos.x - this.x;   
        }
    }
}); 

Might be useful

@parasyte
Copy link
Collaborator Author

@xorinzor Why are you subtracting the absolute origin from the viewport position? Shouldn't it be the other way? Subtract the viewport position from the origin...

@xorinzor
Copy link
Contributor

@parasyte Doing it the other way around creates negative values which result, when drawing, in things like:
(assuming the imagelayer is the background)

webbrawl

@parasyte
Copy link
Collaborator Author

Oh right, because it's changing the source coordinates. 😒 The ImageLayer code needs some internal restructuring, for sure ...

parasyte referenced this issue Jan 18, 2015
- This shows a potential optimization path; melonJS should only use known regions, so we can remove this safety net code!
- Requires Texture [atlas] support for TMX tilesets and bitmap fonts, at the very least
parasyte referenced this issue Jan 19, 2015
…spritesheet

some redundant code to be removed later.
obiot added a commit that referenced this issue Feb 2, 2015
…ed in Tiled

- `me.ImageLayer` constructor was updated to add two `x` and `y`
parameters
- the original `pos` property has been renamed to `offset`, which makes
more sense since this specifies the start drawing offset in the image.
- `pos` is now use as its should be, to specify the default drawing
position of the image in the viewport
- some cleaning in the constructor as well, remove some useless local
var, as speed is not a real issue here.
@obiot
Copy link
Member

obiot commented Feb 2, 2015

note that with this last change, the anchor point is now also relative to the image default position, I'm not sure how this however answer to the original issue :P

parasyte added a commit that referenced this issue Jul 4, 2015
… the viewport boundary

- TODO: Add repeat modes [#603]
parasyte added a commit that referenced this issue Jul 4, 2015
- It looks like Tiled doesn't output imagelayer width/height, anyway.
parasyte added a commit that referenced this issue Jul 11, 2015
- This is necessary when a me.ImageLayer is a child of a floating entity; normalize rendering for screen coordinates so there are no special cases.
parasyte added a commit that referenced this issue Jul 12, 2015
- This removes a hack that would GC the ratio vector on new image layers.
parasyte added a commit that referenced this issue Jul 12, 2015
parasyte added a commit that referenced this issue Jul 12, 2015
- Added `me.video.renderer.createPattern()` and `me.video.renderer.drawPattern()`
- Added `repeat` meta info to `me.video.renderer.Texture`
- Changed platformer background gradient image size to power-of-two for WebGL compatibility
- Closes #603 and #632
@parasyte parasyte modified the milestones: 2.2.0, 3.0.0 Jul 26, 2015
parasyte added a commit that referenced this issue Sep 6, 2015
- This was broken by the ImageLayer refactor.
- Attempted fix was: b20d6ee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants