I believe the reason the effect (parallax or not) does not work is because you used as the host element. Probably some of the properties it uses have no effect on . I assume we're talking perspective and its vendor prefixed counterparts.
So this draws a parallax effect with two background objects but it draws it statically. I'm creating a 2D side-scrolling game and I'm translating my character and my camera position along x axis. So I have to translate my parallax effect with my camera but when I add to background position.x it doesn't work. How can I solve this?
Parallax backgrounds are divorced from reality, you don't need velocities and directions. What you do need is to base the background's X on the camera's position and modified with multiplier to offset the background more slowly so it looks like it is very far away. Different layers of background can look closer by making this magic number bigger, so instead of 0.1f for far away use 0.3f for up close, etc...
It's hard to say when a particular change or feature might be added, @Areeba10. In the case of certain suggestions, there may be technical or user experience reasons why something does or doesn't work the way you might want.
The default Weebly parallax feature does not work on mobile because they just simply use position:fixed to achieve the effect (which doesn't work on any mobile device as far as I'm concerned). It's actually not even "true" parallax (true parallax is where the background scrolls with the foreground, but at a slower pace. Looks very nice and adds an illusion of depth). I wish weebly by default had this version of parallax.
However, third party theme developers often use a different parallax tech in their themes which lets it work very nicely on mobile. I personally bought the "apollo" theme from luminous themes and it has a parallax page type which lets you add parallax sections, and they work on mobile devices (it works on my iphone, haven't tested it on android but they say it works across all devices). It's also the "true" parallax.
I think there's some way to add these mobile-friendly true parallax things to your site without having to buy a theme but I couldn't figure it out, it was too complicated for me. A lot of Javascript stuff which scared low-effort me. So I just ended up buying a theme and using the luminous built-in parallax. But if you're skilled at css/javascript, you should give it a go, you could try using something from codepen which I tried doing.
There is one problem with this method (which I suspect is why it's not generally supported with mobiles) and that is that the image resizes slightly if the browser's URL location bar disappears/appears as the user scrolls. If you can put up with that, you're in luck I hope.
When you scroll a list of cards (containing images, for example) in an app, you might notice that those images appear to scroll more slowly than the rest of the screen. It almost looks as if the cards in the list are in the foreground, but the images themselves sit far off in the distant background. This effect is known as parallax.
In this recipe, you create the parallax effect by building a list of cards (with rounded corners containing some text). Each card also contains an image. As the cards slide up the screen, the images within each card slide down.
Each list item displays a rounded-rectangle background image, representing one of seven locations in the world. Stacked on top of that background image is the name of the location and its country, positioned in the lower left. Between the background image and the text is a dark gradient, which improves the legibility of the text against the background.
Implement a stateless widget called LocationListItem that consists of the previously mentioned visuals. For now, use a static Image widget for the background. Later, you'll replace that widget with a parallax version.
A parallax scrolling effect is achieved by slightly pushing the background image in the opposite direction of the rest of the list. As the list items slide up the screen, each background image slides slightly downward. Conversely, as the list items slide down the screen, each background image slides slightly upward. Visually, this results in parallax.
The parallax effect depends on the list item's current position within its ancestor Scrollable. As the list item's scroll position changes, the position of the list item's background image must also change. This is an interesting problem to solve. The position of a list item within the Scrollable isn't available until Flutter's layout phase is complete. This means that the position of the background image must be determined in the paint phase, which comes after the layout phase. Fortunately, Flutter provides a widget called Flow, which is specifically designed to give you control over the transform of a child widget immediately before the widget is painted. In other words, you can intercept the painting phase and take control to reposition your child widgets however you want.
A FlowDelegate controls how its children are sized and where those children are painted. In this case, your Flow widget has only one child: the background image. That image must be exactly as wide as the Flow widget.
Use the pixel position of the list item to calculate its percentage from the top of the Scrollable. A list item at the top of the scrollable area should produce 0%, and a list item at the bottom of the scrollable area should produce 100%.
You need one final detail to achieve the parallax effect. The ParallaxFlowDelegate repaints when the inputs change, but the ParallaxFlowDelegate doesn't repaint every time the scroll position changes.
As we can see from these results, doing a naive implementation of parallax scrolling, where we first draw the background and then draw the rest of the game on top of it, would not be possible at a fast, smooth frame rate on pre-VLB graphics cards. It was already a challenge to maintain good rendering speed without parallax scrolling in the mix. Because of these speed constraints, many games opted to only redraw the parts of the screen that had changed since the last frame. But these optimization techniques were at odds with parallax scrolling, since it requires large parts of the screen to constantly change.
Instead, the data is distributed across 4 so-called planes. The first plane stores all the first bits of all pixels, the 2nd plane stores all the 2nd bits of all pixels, etc. When looking at an individual plane, each byte thus represents 8 consecutive pixels, but only one of the 4 bits for each of those pixels.
(Why the heck was it done this way? Memory chips at the time were too slow to be able to fetch the pixel data quick enough to drive the screen at 60 or 70 Hz. By splitting the data into planes, 4 bits could be read in parallel and then combined, and that was fast enough).
The EGA can handle all of these bitwise operations for us, taking some burden off of the CPU. But we still need to first read the target data before writing the source data. Reading from video memory causes the EGA to place a copy of the data that was read into internal storage called a latch register. When writing data to the EGA, the written data can be bit-shifted, masked, and combined with the data in the latch register before actually writing it to video memory.
Earlier, I also said that VGA games more frequently featured parallax, and that VGA was easier to program than EGA. This is primarily because in 256-color VGA mode, each pixel always occupies one byte. So all the complexity caused by the need to address individual bits disappears. VGA still has a planar memory layout, but this applies to bytes instead of bits.
The game redraws the entire world every frame, i.e. backdrop, tiles, and sprites. The drawing code is designed around avoiding overdraw (drawing to the same pixel position multiple times) as much as possible, to reduce the amount of video memory writes needed.
With these copies at hand, the game can now simply alternate between the regular and shifted versions on each scroll step. Concretely, it uses the shifted versions for odd camera positions, and the regular versions for even ones.
All of this works exactly the same way in the vertical dimension. For backdrops that can scroll vertically and horizontally, the game creates 4 versions of the backdrop in total: Unmodified, shifted left, shifted up, shifted up and left.
The game also features some levels where the backdrop scrolls permanently, independent of the camera position. This works generally the same way as the parallax scrolling, the only difference is that a counter value is used to determine the scroll offset instead of the camera position. The counter is incremented based on time elapsed. For the horizontal version of this auto-scrolling, the backdrop additionally scrolls in 2-pixel steps, not 4-pixel steps. The principle is still the same, but the game creates 4 versions of the backdrop in this case, which are shifted left by 0, 2, 4, and 6 pixels, respectively. These 4 images are then shown in sequence, before incrementing the starting tile column in the source image.
Tilesets as well as backdrop graphics are arranged in a way that makes drawing individual 88 pixel blocks fast. In bitmap image formats, the data is usually arranged by lines of pixels, so that all the pixels of the top-most line are stored first, then the 2nd line etc. But the backdrops and tilesets are instead arranged into tiles. First, 8 lines of 8 pixels each are stored, representing the top-left block of 88 pixels in the image. This is followed by 8 lines of 8 pixels representing the 2nd block, etc. Each 8-pixel line consists of 4 bytes, storing the 4 EGA bit planes for those 8 pixels. This arrangement makes it possible to seek to a desired tile position within the image, and then read 32 consecutive bytes to obtain all 88 pixels making up that tile.
Very interesting article. ? I am always fascinated about those deeply technical write-ups about programming in the early IBM PC era. You are spot on about the challenges in the software development world being very different these days. Most people cannot keep up with the gurus of retro programming, and I am no exception. But at least I can appreciate it. ?
7fc3f7cf58