View previous topic :: View next topic |
Author |
Message |
sotrain515
Joined: 17 May 2010 Posts: 39 Location: Connecticut
|
Posted: Sun Nov 18, 2012 4:55 pm Post subject: slice as background question |
|
|
Okay, I don't think this is possible, but I might as well ask.
What I want to do is have a slice that has as its parent the "screen" (or the camera; in other words, like a HUD slice), but I want it to draw behind anything non-transparent. My thought is to have it act as sort of a background for the level so that as the hero moves around, the same screen is there in the very background (behind even the tilesets and so forth).
For example, something like when you get to the dark world for the first time in Link to the Past and you're on top of the pyramid. You can see the mountains and castle in the far distance, and they stay relative to the player as opposed to fixed like the "near background" that Link is walking on (tileset). |
|
Back to top |
|
|
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Sun Nov 18, 2012 11:35 pm Post subject: |
|
|
Yes, this is possible. You could use the existing script ('Scripts:Fake Parallax') for map layer parallax, but unfortunately that script causes the layers to jump a little bit whenever the camera starts or stops moving. (This is because scripts are run before the camera position is calculated; I'd like to add some fix for this to the engine eventually). So I wouldn't use that script. Here's an alternative for the special case of a totally stationary background (but which will cost you one map layer):
-First mark layer 0 as invisible. You need to do this because it's not transparent.
set slice visible (lookup slice (sl:map layer 0), no)
-Move your backdrop slice below the map root slice (not below map layer 0; if you put it there it'll still move with the camera)
variable (backdrop)
backdrop := load backdrop slice (...)
move slice below (backdrop, lookup slice (sl: map root)) _________________ "It is so great it is insanely great." |
|
Back to top |
|
|
sotrain515
Joined: 17 May 2010 Posts: 39 Location: Connecticut
|
Posted: Mon Nov 19, 2012 4:25 pm Post subject: |
|
|
Hmm, this does not seem to be working for me. The behavior now is very strange, actually. The backdrop does show up behind the tileset as advertised, but every other slice that I create and then free also seems to leave behind an image that never disappears. Additionally, when I move enough so that the camera moves, the tileset itself leaves a sort of "ghostly" imprint on the backdrop (it looks like a motion blur almost).
Here is a code snippet:
Code: |
script, load level background, begin
variable(backdrop_sprite)
if(level_backdrop) then (free slice(level_backdrop))
switch(current_level) do
(
case(cb:level_first) do
(
set slice visible (lookup slice(sl:map layer 0), false)
backdrop_sprite := cb:sprite_level_one_bg
)
else #all levels without backgrounds
(
set slice visible (lookup slice(sl:map layer 0), true)
exit script
)
)
level_backdrop := load backdrop sprite(backdrop_sprite)
wait(20)
move slice below (level_backdrop, lookup slice(sl:map root))
wait(20)
end
|
The waits are just for debugging; I wanted to see the backdrop appear and then go behind the tileset.
The idea here is that this function would be called whenever a new level was being entered (some levels have backdrops, others do not). The backdrop itself is a global in case I want to change it later. current_level is also global.
Am I doing something wrong? |
|
Back to top |
|
|
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Tue Nov 20, 2012 5:27 am Post subject: |
|
|
Oh, sorry, I see I made a mistake. Slices which aren't descended from either the map root or sprite layer slices weren't actually drawn yet (slices are still an incomplete feature). So I just implemented that. It'll work in the next nightly (don't download immediately -- wait a day). You were using nightlies, weren't you? If you don't want to use nightlies, the only option is to use the buggy parallax script.
BTW, while your script is very neatly written, there is a bug: freeslice(level_backdrop) should be followed by level_backdrop := 0 otherwise it could try to free it again next time. _________________ "It is so great it is insanely great." |
|
Back to top |
|
|
sotrain515
Joined: 17 May 2010 Posts: 39 Location: Connecticut
|
Posted: Tue Nov 20, 2012 9:08 am Post subject: |
|
|
I last downloaded a nightly with the fix you made for the looping chiptune files, so I guess that counts as using them, right? Is there a downside to using nightlies?
As of right now I am basically using a form of the parallaxing script ("parallax" was the word I typed into the wiki's search to find out about this kind of thing, though I still don't really know what it means...). I should have mentioned that; my goal was basically to get a smooth version of it as opposed to the jittery one. I hate that you can see beyond the edges when the camera moves...
Anyway, I guess I'll be trying out the nightly sometime tomorrow. I'll report back and let you know how it works.
Oh and thanks for the debugging tip. Guess I would have found it when I added more than one level... |
|
Back to top |
|
|
TMC On the Verge of Insanity
Joined: 05 Apr 2003 Posts: 3240 Location: Matakana
|
Posted: Tue Nov 20, 2012 4:24 pm Post subject: |
|
|
The downside to using nightlies is that you're more likely to encounter newly introduced bugs. But you can minimise that by only getting a new nightly when you have a good reason to. I'm not going to be suggesting using a nightly when I suspect that there are serious problems anyway.
Parallax is the effect where objects that are different distances from you move at different angular speeds as you move your head. _________________ "It is so great it is insanely great." |
|
Back to top |
|
|
sotrain515
Joined: 17 May 2010 Posts: 39 Location: Connecticut
|
Posted: Thu Nov 22, 2012 7:41 am Post subject: |
|
|
The nightly version worked great! Thanks again. |
|
Back to top |
|
|
|