Hi everybody,
I am making a 2D platform game using QML and i have an issue regarding the scene graph rendering.
I will describe it with an example: I have a QML element describing a swimming pool (what an example ^^). This swimming pool is a rectangle made of two parts, one to describe the background texture, for instance a brick texture and another part to actually draw the water with a refraction shader effect.
Here is a screenshot of what i want to do:
As you can see it’s already partially done, but in fact, there is an ugly hack behind this screenshot.
The brick background is a QML element and it is a sibling of the player sprite and the other physical elements. And the water foreground is another QML element outside the world element (root of my game elements) which use the world as source and with its x, y, width, height hardcoded from the brick background element, so the script looks really ugly and is not maintainable. It looks like this:
Game {
World {
id: world
SwimmingPoolBackground {x:0; y:0; widht: 200; height: 100 ...}
Player {}
}
Foreground {
SwimmingPoolForeground {source: world; x:0; y:0; widht: 200; height: 100 ...}
}
}
And i would like it to look like this:
Game {
World {
SwimmingPool {source: parent; x:0; y:0; widht: 200; height: 100 ...}
Player {}
}
}
Or at least something like this:
Game {
World {
id: world
SwimmingPoolBackground {id: swimmingPool; x:0; y:0; widht: 200; height: 100 ...}
Player {}
}
Foreground {
SwimmingPoolForeground {source: world; anchors.fill: swimmingPool ...}
}
}
But of course i did not achieve to do this the way i want…
- Why i cannot directly put the swimming pool background and foreground directly in one element ? Because the refraction shader effect need to know about the midground objects.
- Why i cannot set the source of the shader effect to be the world ?
Because in this case the shader effect will try to draw itself because it already belongs to the world.
- Why i cannot split my swimming pool in two parts, background inside the world element and foreground outside (to use the world as source) but anchored to the background ?
Because since the foreground is not anymore the sibling or the child of the background i cannot anchor it.
So, i am looking for a nice and smooth way to handle this case without hardcoded values and if possible with only one high level element.
Maybe by temporarily excluding the rendering of the foreground and display it afterwards but how ?
Any idea ? ^^
↧