How do I efficiently render a pixelated line? - unity3d

I am working in Unity2D and have a character who can shoot in all directions. The game has mobile controls and the player will choose his shooting direction with a joystick on the right side.After testing I found it rather difficult to correctly determin where the shot is going to land at. To convey this to the player I wanted to add a sort of "shooting line of sight" to the player. It is moving around the player according to the joysticks position. (As seen in the picture)
Because I want the line to be pixelated (to match the design theme of the game) I cant use the standard LineRenderer component as it doesn't support such pixelated lines. So I started looking for solutions to this problem and stumbled upon Bresenham's line algorithm. After implementing it into the game I knew which x, y coordinates I had to fill with a pixel. Currently every single white pixel in this line is a GameObject with its own SpriteRenderer and a single white pixel as a sprite. In my test scenario up to 400 pixels where rendered at once. I am already using an object pooling system to minimize the performance drag. Moving this line around drops me from around 1100 Fps down to like 200 Fps in the editor. I know it will be slightly better in the build game but I am sure it will take a toll on older mobile devices when enemys, animations etc. are present in the level.
So my question is: Is there a better or more efficient way to render the sprites? Or (preferably) do you have a better idea on how to render this line at all without creating ~300+ GameObjects. (e.g. Shaders (Zero experience), drawing on a texture)
I am grateful for any ideas that lead me into the right direction.

Related

Why can I see the inside of a room as soon as I cross it, in Unity?

I am currently working on a 3d game in Unity, and I am working on the level design using ProBuilder. I basically created a huge cube which I "flipped normal", and a second one way smaller
which, as the other one, I flipped normal, but as soon as I crossed it while turning backward I could weirdly see through the small cube, which makes it feel unfinished. How could I fix this issue?
Normally in 3d games triangles can only be seen from one side. Usually this is not a problem because walls have some thickness. Since you clearly have paper thin walls made of only one layer of triangles this is exactly the result you should expect.
In short add the other side to your walls. The simples way is to duplicate the existing triangles and flipping them. Walls will still be paper thin of course. Later you should probably make them thicker.

How to override physical marker in vuforia AR Camera in runtime?

How can I override the physical marker in unity to just make the physical marker invisible in camera while detecting any object.
Like in this video:
https://m.youtube.com/watch?v=R_F1LvK5gCk
And many other videos.
This maybe isn't the correct answer but, I'll put my ideas here because sadly it doesn't fit in the comment section.
I just watch the video and some of the reels they show as his works.
First, yes, in deed they make the marker a sort of invisible marker, but if you look closely, like a 0.25 speed and pushing space bar very fast to look it in slowmo, you can see a kind of "artifact" in between the girl's fingers that makes me think there's no invisible marker but a texture that are covering the marker. Maybe a cylinder that gets his texture from the video camera input.
Now, how I do that?
There are several ways to get the pixels from the webcamera, even Unity has one function. The trouble is, I dont want all the pixels but a little tiny part of the camera render, specifically the one's around my marker.
In my experience, and in his examples, they are using OpenCV, another unity plugin, so they can track anything, from faces, hands, or markers, so I can't be quite sure they are using Vuforia alone or in combination.
My idea is, with OpenCV you can catch your marker and his contour, then ask for the pixels outside the contour of your marker, those pixels will be the skin tone of the person and latter apply them as a texture over some plane or 3d model that can cover your marker. You can have the pixels at right side and left side of the marker and use a average function betwen them so it could look nice or if you like the adventures you can try to use some kind of digital images processing method to get bether results.
I'm not sure if you can have the pixels arround a marker just using just Vuforia. Honestly I've never try it before.
Well, that's my idea.
If you can get it better I'll like to hear about it.

Breaking up a sprite in cocos2d

I'm making a 2D plane fighting game for the iPhone in cocos2d. I'm trying to make it so when you shoot an enemy plane, it breaks into a couple of separated pieces that will fall out of sight. What is generally the best practice for breaking one sprite up into many? should I create new images for each separate piece, or treat the initial image like a sprite sheet, and make a new sprite from segments?
Please look at this tutorial
It makes a grid of points then moves the internal (not-edge) ones around randomly a bit so it's not all perfect triangles. Then each update it moves/rotates the triangles separately--then draws them all at once.
You treat the whole thing as a sprite, so can run any of the usual actions on it. This example uses CCMoveBy to move the whole group down off the bottom.

How to handle a game world that wraps, using cocos2d on the iPhone

I have a game world that's much bigger than the view port, the main character stays in the center of the view port at all times and the background layer is moved around to give the impression of the character moving. I want to make it so that the game world wraps, meaning if the the character keeps traveling either left or right they will eventually end up back at the starting position. There will be moving entities in the game world so the biggest problem I foresee is that if you go to the far right of the map you should be able to see any of the moving entities that are within the first small section of the far left of the map.
I've thought a bit about this and any solution I've come up with seems far too complicated. Like creating two identical game worlds side by side and moving them around accordingly. I live in hope that there is an elegant solution to this. Any expertise you can share would be greatly appreciated.
I'm using cocos2d on the iPhone just in case that makes any difference.
An example might be to have an x,y offset for your camera, and a multidimensional array of sprite objects.
As the player moves, the offset value changes, e.g., xMove = -1.4 and yMove = +2.6.
Then you would iterate and change the positions of all the tiles by that amount.
Next, you would identify the sprites that are too far away from the center of the screen (0,0) and re-position them to the opposite side, so they will always be visible.
This would all be done on the same scheduled 'tick' so no graphical artifacts occur.
I'm pretty surprised no one has made a wrappable tile map yet for cocos2d.
I can't give cocos2d specific advice, but I would say the most common way to do this is to create one game world, draw (parts of it) multiple times and make sure that your logic for things like collisions and AI checks for wrap-around where appropriate.
So if your player character is close to the corner of the world, you'd draw the world four times with different offsets. This needn't actually draw every single thing in the world four times any more than you would normally need to draw the entire world when only a small part of it is on-screen.

How to create a level with curved lines with cocos2d + Box2d on the iphone?

I'd like to create a game that has levels such as this: http://img169.imageshack.us/img169/7294/picdq.png
The Player moves "flies" through the level and mustn't collide with the walls. How can I create such levels?
I found that piece of software: http://www.sapusmedia.com/levelsvg/
It's not that cheap, so I wonder whether there is another way to create such a level as shown in the picture above...?
You can do that pretty easy by reading the color value of pixels at specific places of the level. Take for instance that your level background is white and the walls are black. In order to perform collision detection, whether your character had hit the wall, you would do the following:
-take your character's position
-look at the color values of the pixels of your map that overlap with character's bounding box or sphere at that position
-if any of those contain black color you have yourself a collision :)
Now if your level is all colourful, you would want to build a black and white mask texture that would reflect the wall surfaces of your actual map. Then use the coloured map for drawing and the bw map for collision detection.
I'd spend a good solid couple weeks getting caught up on Objective-C, Xcode, Interface Builder, and Apple iOS documentation. There are many good tutorials out there and sample Xcode projects to download and run on the iPhone/iPad simulator.
If just starting out, some of those quick startup libraries can rob you of the intimate knowledge you'll need to create the intricacies and nuances you'll need when your application starts to reach outside the boundaries of the code sandbox. Not bad to use as learning tools or to speed up development time, but I'd advise against using them as a crutch until you strengthen your developer legs. Crawl. Walk. Run!