creating CCTMXLayer dynamically - iphone

I try to create my own tile map dynamically such as some buildings created with the help of database. I try to use CCSprite on object layers. However, when i scroll the map, also CCSprites' move too. I don't want to move all of the Sprites whenever player scrolls the map. (For performance issues)
Then, I decided to create my own CCTMXLayer over the background layer. How can i create my own CCTMXLayer dynamically?

You can modify an existing tilemap using CCTMXLayer's setTileGID method, so create a tileMap in Tiled (or whatever editor you choose) with a single tile.
Then once you have loaded the map into a CCTMXLayer use the setTileGID to change what the tiles are.
Alternatively you could create a new CCLayer and then just add a sprite for every tile in the game, however, you should probably user a textureAtlas or a batchNode if you decide to take that approach. Then to move the map you just change the position of that layer.

Related

how can I make a player hidden by terrain always visible?

I am making a 3D isometric game, in my game, there is a lot of holes and the player can go into them, but the problem is when he goes into one of them he becomes invisible, I can,t move the camera it will change the concept I tried using shader like the one in this video but it makes the entire terrain transparent and glitchy (I am using unity terrain) so I am stuck and I need Idea how to make the layer visible inside the hole
What you're asking can be achieved in multiple ways, depending on your render pipeline and requirements.
If you're working with the Universal Render Pipeline (URP), you could create a Forward Renderer asset and create a custom render pass whenever your player is occluded by terrain.
You could assign a new Layer to the player, such as "Player", then select or deselect said mask from the Filters > Layer Mask properties of the Forward Render Data. Then assign the same or a custom material for when the player is occluded by terrain.
Alternatively, you could create either a cutout or a dither shader using Shader Graph, on which there are many tutorials
Camera GameObjects give you the option to select what layer you want them to "see" (render) using the culling mask. Think of layers as grouping GameObjects and giving that group a name.
You can have multiple cameras at the same time each one with a different name and different layer to render, or even change the viewing layer of a single camera depending on changes happening in the game.
Assign a layer tag in each of the terrain elements in your scene and have the camera render them accordingly and "cull" the rest.
Very helpful documentation on layers and camera culling mask.

Move multiple child objects with parent in Unity + LeanTouch

I am facing some issues using LeanTouch asset.
Context:
I am creating a Human Anatomy application using Unity3D and Vuforia. My task here is to enable user to select, drag, move human skeleton and different organs to inspect them. I was able to achieve this as long as my GameObject does not have any parent.
For example, I have a Heart 3D model having 3 child gameobjects. If i use leantouch's selectable and other drag translate. It works with no issues. But as soon as i apply the same components to the parent Heart Object. It does not work.
If you want to try it out. Create 2 or 3 3D cube objects in unity. Then create an empty gameobject and place 3d cubes into it. Now try to add lean touch components to the parent gameobject. It won't work.
Thanks

Combine two sprites into prefab Unity

I have two sprites I downloaded off the asset store on my canvas one is a building, one is the foundation the building sits on.
However, in my game these two sprites will always be together. I'm going to be creating many instances of these on my map and I don't want to have to drag each piece on to the map individually and position them. So I was hoping to highlight them both and turn them into a prefab so Id just have to manage one object instead of dragging around both sprites.
I could just open them in photoshop and combine the two images but I'd prefer to just put them together in unity and leave my sprites modular.
You can create a empty object. This object is parent object.
Then in hierarchy window, you drag 2 sprite to this parent object. So 2 sprites is child of parent object. Make this parent object as prefab.

How can i switch multiple layer with same sprite?

I have 6 sprites on screen, now after particular time, I want to reload that 6 sprites without affecting screen. (with removing old & add new images)
like objects are changing in one frame.
I use Layers for this, but I am not able to assign two same sprite in both layers.
How can I switch multiple layer with same sprite?
got the answer.
just detach current layer.
initialize next layer.
overwrite ArrayList (in my case, i have taken arraylist of sprite) of sprite with required images.
attach that arraylist to newly created layer & then attach that layer to scene.

Scrolling a game environment in various directions

How does one create the game "area" for a scroller game?
How does one then put various obstacles with collision detection along this scrolled environment.
I want to try out a project which will allow the user to scroll to a certain direction in order to progress through the game.
How does one map the objects within the environment and then move what I guess is the "camera", the view of the environment.
Thanks
The trick is that there is no "area". The only bits that exist are what's under the camera (the view you currently see) and a small surrounding area giving you time to prepare more world in the direction you are moving..
Your world coordinates need to be defined as do the starting coordinates for the view. You use tiles to create the view - at its simplest that is 9 tiles, one you are currently "on" and one in each direction. If you look at the keyboard numberpad you are "on" the 5. If you move a little to the top right you are displaying parts of tiles 8, 9, 5 & 6. At that point you would create new tiles in case you move further. As you leave tile 5 you would probably release tiles 4, 1 & 2. Nine tiles may not be the optimal number of course.
If doing this with UIViews (probably not the high-performance choice) you are probably going to define one big view that can handle all the tiles and tile them onto the view (add and remove subviews), setting the large view's frame to define your camera position. As you move you change the frame to move your camera, when you need to shuffle tiles you move both the tiles and the frame to recenter giving room to move further within the coordinates of your view.
Collision detection is pretty simple since you define your own dimensions (the thing representing "you" in this world) and objects in your view have dimensions you can check against. CGRectIntersectsRect might be the simplest function to use but if you have irregularly-sized views it will get more complicated.
This answer about implementing a cyclic UIScrollView is a similar idea but it only handles scrolling on one direction.
This is a pretty common topic and if you google you will find a lot of sample code and tutorials around.
From the game logic side:
All your objects (lets call them gameobjects) should have a coordinate (x and y position) in your game world. You will keep all your gameobjects in a list. Your player object will be a gameobject too. Usually your "camera" position will be relative to your player objects position. I.e. the player will always be in the center of the screen. To determine the current "screen" position of your objects you will just subtract the camera position from your objects "world" position. Collision is usually made with simple rectangular overlap checks. You give all your objects a width and a height attribute and do your collision checks using x, y, width and height.
From the display side:
If you want to display many objects (i.e. Player, Enemies, Obstacles and so on) the best way to implement something like this is to use an OpenGL View. In this view you can display all Objects as Textures that are mapped to Polygons. You can use a library such as cocos2d which already has all of the code to achieve this easily.