-
-
Notifications
You must be signed in to change notification settings - Fork 646
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
Background image layer position is ignored when ratio defined #737
Comments
I think so. Are you using the 3.0.0 WIP? This was just fixed recently in #725 Is there also a bug with the actual positioning? I mean, does it correct itself to the expected position when the viewport moves, or is the correct position initially set on load? (If the former, then this bug is fixed! If the latter, then we have a different bug!) |
I've merged my fork with the recent changes. Now it doesn't jump when the camera moves, but the background is always stuck to the top of the screen no matter what the y position is set to in Tiled. |
https://github.com/melonjs/melonJS/blob/master/src/level/TMXLayer.js#L260 It's trying to position the background in the room using the anchorPoint relative to room boundaries, completely ignoring the Tiled position. However, even going along with this logic it's still broken. If I set any anchorPoint in tiled it fixes the image to the top left of the viewport. I suggest the following positioning logic for image layers, to keep up with the new positioning for sprites:
This allows Tiled to set the initial position of the image in the room when the viewport is at position (0,0). Then that image is scrolled according to the ratio of the viewport position offset from the origin of the room. It's much simpler, and more precise than guessing at an anchorPoint. Also Tiled's position isn't ignored! |
Use |
I'm guessing your browser didn't load in my latest comment when you posted that. |
I'm probably just confused by how you're using Specifying |
I really think the image should be positioned in the room according to its "position". I mean that makes sense, doesn't it? The anchor point is fine if you treat it like a Sprite's anchor point, but I really don't like having the image's position ignored just because the ratio isn't 0.
|
Disadvantages to anchorPoint viewport boundary positioning:
|
Would you mind sharing an example that displays the issue for debugging? The image position is purposefully ignored when For some history, To answer your comments:
|
2&3. I'm talking about from an artistic perspective. You don't create visual assets with a command line. When I'm constructing a level, I don't know or care about what percentage or pixel position it ends up as. I want the image to be positioned where I see it positioned in Tiled when I'm creating the level. Only after seeing what the finished product would look like, then I can worry about what pixel/percentage offset it translates to. Having to go back and do extra math to calculate an anchorPoint adds a very large load of extra work when you're planning on constructing 1000 rooms, and many with multiple parallax background layers. Taking Tiled's position into account + the new way anchorPoints are positioned with sprites, you can achieve the same effect as anchoring to the bottom of the level by setting the y position in tiled to the bottom, then setting the anchorPoint to (0,1). This does not make the anchorPoint inaccurate, it's just a different way of thinking about it. |
Ok, now take what you see in tiled, and cut out a small rectangle of it to represent the viewport. With this in mind, here are the problems to solve from a logic perspective. (This is the reconciliation I mentioned.)
This is not an issue unique to melonJS. For example: http://www.gamasutra.com/blogs/DavidDionPaquet/20140601/218766/Creating_a_parallax_system_in_Unity3D_is_harder_than_it_seems.php?print=1 The videos here demonstrate the viewport rectangle scrolling across a map with parallax layers updating in real-time. If I had my way, Tiled would do this, and we would just replicate it within melonJS. Since that isn't the case (though could one day happen) we need to work within imaginary boundaries and take a "best guess" approach to resolving the conflicts between what Tiled shows, and with what's expected to happen at runtime. |
I don't follow; |
You just gave me an idea; I think we can solve both of our issues.
|
That's kind of what I want to do. But I'm still looking for the closed-form expression to make it happen. (!) |
Isn't it as simple as adding Tiled's position to the end result? Or am I missing something? |
Just that adding the position would have the result that I described. That result is unexpected when |
|
Honestly, having an expected result only at anchorPoint <0,0> is better to me than having nothing at all. Though I'm not entirely sure what you mean by the result being unexpected. It's ugly in tiled, for sure, if your anchorPoint is something other than <0,0> and you're using the image position to control a pixel offset in addition to the anchorPoint. https://github.com/melonjs/melonJS/blob/master/src/level/TMXLayer.js#L314
|
Yes, but we're not just trying to solve another use case, here. The goal is to simplify how the inputs behave, so that they are easier for humans to reason about. Take this idea, for instance: perhaps the position itself describes the anchorPoint.x = imageLayer.pos.x / (map.width - imageLayer.width);
anchorPoint.y = imageLayer.pos.y / (map.height - imageLayer.height); While this can be done manually and placed into a layer property, it could also be initialized with this code in the default case. If I'm not mistaken, that takes care of the Tiled positioning issue, without changing any of the scrolling behavior. That behavior has gone through three years of evolution, and I'm hesitant to introduce another offsetting mechanism. In other words, the position which you define in Tiled is the Do you agree with that? |
That sounds good. So then manually defining the anchorPoint in Tiled would negate any effect the position had on the image. I'll try and create a simple example where the anchorPoint isn't working for me. Too bad there's no parallax demo. |
Here's a patch to try, when you are ready to test a fix: diff --git a/src/level/TMXLayer.js b/src/level/TMXLayer.js
index 6e16417..5966290 100644
--- a/src/level/TMXLayer.js
+++ b/src/level/TMXLayer.js
@@ -139,7 +139,10 @@
* @default <0.0,0.0>
* @name me.ImageLayer#anchorPoint
*/
- this.anchorPoint.set(0, 0);
+ this.anchorPoint.set(
+ x / (viewport.bounds.width - this.imagewidth) || 0,
+ y / (viewport.bounds.height - this.imageheight) || 0
+ );
}
else {
if (typeof(settings.anchorPoint) === "number") { |
I'm thinking with that implementation if you want the image to be anchored to the bottom of the room the image would be off-screen. Maybe it makes more sense to pick a point inside the image based of closeness to the room boundaries, instead of always using the top-left corner. EDIT: Nevermind. |
#738 |
Your patch works great, I just added |
Ok, I'll commit the patch with the syntax error fixed. As mentioned in #738 (comment) You're missing the |
- Seems the Wolfram Alpha optimization applied the ratio on the wrong side. - This fixes the scrolling and positioning, according to further tests.
Here is an example:
https://www.youtube.com/watch?v=KRjDkCDcC-I
Is this a known issue?
The text was updated successfully, but these errors were encountered: