# Tag Info

19

Divide the position of each layer by the “distance” you want it to have from the camera. For example: Create a couple of variables to represent the camera position, cameraX and cameraY. Set these to equal the position of your character, possibly adding on a bit extra in the direction of movement. The main layer would just be positioned at mainLayer.x = -...

6

Whenever you do a float operation, some rounding errors are bound to occur. Because you are adding each specific layer's position change on every frame, eventually these errors add up and become noticeable. Say you have a max error e in each multiply operation, then with your algorithm the frame 1 position is: layer1.x(1) += cameraTarget.moveX * layer1....

6

Basically you want objects to move faster, the closer they are to the 'camera'. How you implement that is up to you. I assign each of my layers a depth, and then as I scroll the scene, for each layer I divide that scroll by the depth of the layer, so that layers that are further away move slower.

5

You just move the backgrounds despite them being meant to be static. For example, your character (and the camera) move 5 units to the right. Move the background right behind the character to the right by 1 unit. Move the background behind the other background by 2 units. Move the next background by 3 units, etc. The furthest away background (i.e. the ...

5

A layer that's "further back" would need to scroll at a fraction of the speed of the foreground layer. Half the speed implies double the distance. Other effects like tinting to simulate fog, etc, might also add to the illusion.

5

Your question is a bit rough but if I'm following correctly, you want to make it so the background is stretched horizontally as it moves towards the bottom of the screen, giving it a somewhat isometric view and a more angled perspective. Just as a warning, I've no direct android development experience myself so this is going to be largely theoretical. ...

4

Your problem happens when you reuse the background and put it the other side. Change this: if (positions[i].X <= -texture.Width) { positions[i].X = texture.Width * (positions.Length - 1); } To this: if (positions[i].X <= -texture.Width) { positions[i].X += texture.Width * positions.Length; } So, add (+=) instead of overwrite (=)....

3

I can't answer specifically for Andriod as I have never done anything for it, but generally you will want to only draw the portion of the map that is visible. It requires much less memory to do it, and shouldn't mess with collision at all. In fact, you will only need to check for collision on the objects you are drawing rather than the entire map. If you ...

3

Looks like you you have duplicated the background position twice in the else part. I've inserted the 2 below else { background.position = ccp(background2.contentSize.width / 2, background2.position.y - 50 * delta); background.position = ccp(background2.contentSize.width / 2, background2.position.y + background.contentSize.height); } Added: After ...

3

The result you get (left image align) is correct given the math you use. What you want is that when near image is reaching right edge: nearImage.position.x == nearImage.width - viewPort.width we have also far image reaching right edge : farImage.position.x == farImage.width - viewPort.width All that should happen in the same time, so the speed ...

2

I think you should make the algoritm work differently. Place your "view" in an array (2D tilemap) and then look forward eg. 20 tiles. The "scroll" is the amount of pixels for 1 tile, so if your scroll becomes negative, just add the size of a tile, and increment offset for "view" with 1. Repeat until scroll pos is postive again. Then repeat this pattern ...

2

First you will need to have as many sections as are needed so that you can fill the size of the screen plus one. So if you have a screen width 480 and a section width of 480 you need two sections to repeat. If your section width is only 240 then you would need 3 sections. I would step back from using this CCParallaxNode for now and just get a single layer ...

2

to more clarify I want to use occlusion culling and batching at the same time. Occlusion culling? You are drawing tiles, not 3D polygonal meshes. They're axis-aligned. It takes very simple math to know exactly which tiles are on-screen. Plus, even for Android hardware, drawing a few things off-screen will do nothing to your performance. As long as you're ...

2

Parallax scrolling is just using a set of layers moving with different speed. each layer can be a tilemap, just a sprite, or anything else. normally the most front layer is a tilemap and you only check collisions and other gameplay features with that layer. just keep in mind parallax scrolling is going to simulate 3d projection using only 2d objects, so ...

2

I am creating a simple ambient/explorer platformer. Because I want the player to only be able to see a new area once they have reached it, I decided to split up the world in rooms. However, I also want to implement a slight parallax-effect. These effects always manage to look awesome. How do I create a smooth camera movement for this? The code you ...

2

It really depends on what you're trying to render. For example, if you're rendering layers of clouds that are transparent to the background but not necessarily to each other, one useful trick is to draw the background, then non-transparent cloud layers, then draw the background again at 50% transparency over the other layers.

2

It sounds like what you're after is a way to streamline and optimise your workflow. I would take the approach of defining various levels of foreground and then assigning each foreground element an index. You would then use your horizontal and vertical multipliers on a collection of sprites that have been assigned to a certain layer. Example: This ...

2

You should use delta time instead of total time. And keep the "running total" in your offset variable, instead of in time. renderer.material.mainTextureOffset += new Vector2 (Time.detlaTime*Speed,0); Then, when you come back from a pause, the mainTextureOffset is where you left it.

2

I can't speak to using AndEngine, but the logic for an infinite scrolling backdrop is pretty engine-agnostic. Let's simplify and imagine the case where you are alternating between two images (it doesn't really matter how many you have). Imagine a number line for x, from zero to infinity. Now imagine that your first image (image 0) is placed on that line ...

2

In unity, SortingLayers (or camera layers for that matter) are not groups of object you should see them as tags : specifically for the sprites, sorting layers are used to define the order of render of the objects. you can go through all the sprite-renderers and check their layers and apply something to their transforms but that will consume "a lot"* of ...

2

Parallax scrolling could be seen as a kind of differential scrolling. Differential scrolling is simply an effect whereby two (or more) pieces of content scroll at different rates proportional to the differences in some property shared between the pieces of content. For example, as in the demos linked in your second example. The three vertical columns of ...

1

I'm not familiar with MonoGame. Have you thought about drawing your parallax background at a reduced resolution to a render texture? Scale the finished render texture up to the original size and render it to the screen. If you create the render texture at half the width and height of the original, you need to overdraw and blend only 25% of the fragments in ...

1

This depends whether you have: Just a small number of different levels of parallax depth A continuous (i.e. near-infinite) number of different depths For 1), it will probably be most efficient and simpler to just treat the levels independently and query the appropriate rectangle in each level. 2) is harder. You are effectively querying a subset of a 3D ...

1

The position of the child is the relative position of the child plus the position of the parent. So the x position of the child would be something like: tempsprite->getChildren()->objectAtIndex(0)->getPositionX() + tempsprite->getPositionX();

1

You need to test it on your target platforms. Canvas implementations vary hugely in their performance, and a technique which is an optimisation on one may be a pessimisation on another. If the layers are going to be "sparse" with few objects, I'd recommend just drawing those objects (in order, using painter's algorithm). However, if there are lots of ...

1

I have used Parallax background in my game and I don't understand, why should the vertical and horizontal ratio should be any different. I have only 3 layers. Static background, parallax layer that moves half the speed as the front (game) layer. In my game, there's a lot of vertical and horizontal movement and it simply looks the best when the vertical and ...

1

Have you looked at the AutoParallax example code in AndEngine? It creates the parallax background layers iike this: final Scene scene = new Scene(); final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5); final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager(); ...

1

Instead of using mScene.setBackground(background) take a look at background.attachParallaxEntity(). The AndEngine example for autoparallax is a good example on how to do this. Here's the critical part: final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5); final VertexBufferObjectManager vertexBufferObjectManager = ...

1

I'm unfamiliar with Unity, so I cannot help you with specifics, but it sounds like what you need is to implement a GUI means of fine-tuning those values during run-time with, say, a set of sliders or numeric fields. It would be fairly simple to implement fields to alter whatever values you're determining (scale, speed, etc) during run-time which gives you ...

Only top voted, non community-wiki answers of a minimum length are eligible