How do I activate 2 cameras at the same time? The first camera follows the character and the second camera follows the character more slowly. After a while we can't see the character with the second camera but the point is each camera renders a special game object. The second camera renders the back game object. So two cameras with each other make better scene moving. Is this possible?
I believe you are looking to implement a scene background parallax where the background appears to be moving across the scene slower than the forground.
Take a look at this video about separating your scene's layers. There is a quick fix solution in the first few minutes of the video, and a longer re-work that is a good idea to think about.
Parallax Scrolling
Related
I was going to use the VideoPlayer to render to Camera Near Plane, but I also want to display subtitles for the video for the sake of accessibility. I'm wondering what the best way to do that is.
I can't see anything on a canvas if I render to Near Plane. I'd like the video to appear in front of the scene so that I can have the scene there once the video is complete.
Do I need to be using a render texture to achieve this? Seems like a render texture might incur some unnecessary overhead for my purposes, but I could be wrong.
The idea is this:
Far Background - Scene
Background - Black Image (so i can fade to scene)
Middleground - Video
Foreground - Subtitles
More info:
This is a 2D point and click adventure game with a pre-rendered cutscene.
You could do this with a render texture, place it in front of the camera at an exact distance and size, but I wouldn't. Probably would be a different camera anyway for lighting or clipping purposes.
I would use a second Camera, rendering over top of the Main Camera, with the subtitle UI's canvas targeting the second camera's screen space, and clearing depth only. It will render what it sees, but with a totally transparent background. Then, you can render your video on either the main camera's near plane or the new subtitle camera's far plane.
You could put your black square in front of this camera, too, though it would be in front of the video. It could be UI on the main camera, or stick a third camera in between them. You might have to worry about performance if there are too many cameras, but I have used two or three before to no noticeable performance hit.
Robert Mocks's answer is perfectly tenable and makes sense to me. Thank you for that!
What I decided to do instead was use a RawImage so that I wouldn't have to deal with extra cameras. This way I can use the canvas as I normally would and don't have to deal with render textures.
This involves using the API Only setting along with the following code:
rawImage.texture = videoPlayer.texture;
That seems to work well for me.
Video of issue in action: https://streamable.com/pkrog
The video linked above does a better job of explaining the issue than I could, but I'll give it a shot.
I have my walking/idle animations setup in a 2D Freeform Cartesian Blend Tree, which is working perfectly, aside from when I'm moving between transitions. So idle looks great, until I hold 'W' to move forward, then for the half second it's blending between idle and walking, my model gets very twitchy, then after it's done blending, it's smooth again. Same thing happens every time the Animator has to transition between different animations.
Any idea what could be causing this?
It might have to do with the fact that you update your camera in fixedUpdate and your animations are updated at the game normal update rate. So the different rate at which both your animations and your movement/camera/body updates makes it jittery.
I have a pretty large and full scene and therefore gets a lot of draw calls.
Sometimes I display a video in the game, which covers the entire screen.
When I tested my game with Unity's profiler tool I noticed that the camera still renders everything (although occlusion culling is enabled and calculated), and it causes the video to lag.
My question is how can I disable the camera?
When I disable the Camera component or the camera's GameObject I get a warning ⚠ in the game view that says No camera is rendering to this display. Which, I guess, is not good (correct me if I'm wrong).
So I was wondering if cancelling the culling mask on the camera (by setting it to Nothing) would force unity to stop render the scene.
Or does it still do some work in the background?
(Like with UI elements that still being rendered even though they are fully transparent).
Thanks in advance
I have a pretty large and full scene and therefore gets a lot of draw
calls.
I recommend activating "Instancing" on your materials, it can greatly reduce draw calls.
When the UI Pops open, it can help removing the "Default" layer (or whatever layer the majority of your renderers are) from the active cameras. You can do this easily with layer masks. Or you can just set Camera.main.farClippingPlane to 1 or any low number.
I am writing a game in which there are thumbnails of mini games displayed in a grid, CCSprites in a NSArray. One of these is then scaled and moved to create a zooming effect. Once it has zoomed in it is hidden to reveal the actual "live" minigame (a CCNode), which has been added to the scene invisibly while the zooming animation took place. This means that if the minigame looks exactly the same as the thumbnail there is a seamless transition. After a few seconds, the zoomed in thumbnail reappears covering the actual minigame and zooms out.
My question is, how can I take a snapshot of the actual minigame and use that as the thumbnail so the user cannot tell that the thumbnails are not actually real games? This would have to happen in the split second when the game has paused but the sprite has not reappeared.
I fear that my explanation is not very good, but I hope that someone will understand it!
Ok... solved it. I guess I should have searched more before posting.
After a while, I came accross these two articles:
http://www.bit-101.com/blog/?p=1861 and
Replacing image in sprite - cocos2d game development of iphone
I used the code in the first article (after adjusting it for the retina display) to create an array containing the pixel data. This is then inverted (its upside down to start with) and then pushed into a UIImage. I then init a CCTexture2D with the image and replace the existing sprite texture with this.
I hope this helps someone else at some point.
I'm making an iPhone game in cocos2d.
I was wondering how I would make the camera / the view follow a specific sprite?
would I use the CCCamera class?
Yes, CCCamera would work. However, it has some drawbacks that make it undesirable for some uses. Moving the layers respectively all other objects relative to that sprite may be a better solution. It depends on the game.
First, read up what the different approaches and their drawbacks are, you can get a lot out of this cocos2d forum thread:
http://www.cocos2d-iphone.org/forum/topic/5363
It would be helpful if you could describe what your game is about and why you need the camera attached to that sprite.
For example, if you're thinking of a running game like Canabalt, i would not use the camera to scroll over the world, but instead scroll everything relative to the player (towards him) with the player sticking at about the same x coordinate while running. Perfect examples of games where you would not move the camera at all are the iCopter games, they are basically simplified versions of Canabalt. Notice that the player sprite always stays at the exact same x coordinate, and the game world just scrolls
Scrolling the camera itself in my opinion makes the most sense if you have a large game world that the player can traverse in all directions, and the number of objects are simply too numerous and also moving about in various directions, so updating their positions individually each frame would be both overkill and prone to errors. And since the game world is so huge, you would want to use the camera's position to limit what is drawn on screen.
use CCFollow actions
Like these :-
[self runAction:[CCFollow actionWithTarget:(u r hero) worldBoundary:CGRectMake(0,0,1050,350)]];
it will helps