Tag Info

Hot answers tagged

17

You want to create a couple of variables representing the camera position - cameraX and cameraY. You then want to set these to equal the position of your character, possibly adding on a bit extra in the direction of movement. To position the main layer, it's just: mainLayer.x = -cameraX; for the middle layer, something like: middleLayer.x = -cameraX * ...


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 * ...


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 ...


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 ...


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 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

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 ...


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 ...


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

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

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.


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

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 ...


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

An idea: I would think a camera for the front layer is enough. Placing sprites a distance away from that on the z plane, and lerping the distance gives you a fraction on which to move that back layer. For example, an object distance 10 from the front camera moves 1/10 in the background layer. An object of distance 2, would move 1/2 in its respective layer, ...


1

The new iPad has a resolution of 2048 x 1536. That means in landscape mode (assuming you don't want to stretch the image) your background image would need to be 1536 pixels tall and at least 2048 pixels wide if you don't want a repeated portion in the same scene. Now you can either scale down for the other devices, or you can create additional art for the ...


1

In my experience this is best solved by simply transforming the co-ordinates that you are about to draw by a scrolling amount (deviation from the starting point). You mentioned in a reply to another answer that you are using OpenGl. You can use glTranslate to move objects in your scene. glTranslate(x, y, z) ...


1

The object should be offset along with the parallax in addition to its movement within the layer. When doing parallax rendering, the layers themself aren't actually moving, its just the viewport that changes. Anything on the same depth as a parallax layer should be moving along with it, and if it is moving, you should simply add that on top.



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