How can I create a tile, overlay for a scene in Cocos2d? - iphone

I'm new to Cocos2d, but I can't seem to find the answer to this. I want to add an image that is mostly transparent as an overlay to my application. The image is overlayed on the app, and does not respond to screen taps. All gestures should "pass through" to the application.
The overlay image should actually be tiled. It's a small image that should repeat both horizontally and vertically.
How can I do this? In fact, this is an overlay that I would like to display for the duration of the entire application-- not just one specific scene. Is there a simple way to do this?
The point of my overlay is that I'd like to create a pseudo-scan line affect for a game which has an "8-bit" tone. The scan lines will be generated by applying the overlay to the game. The overlay is non-interactive and should always exist. So, this isn't a "tile based game", but I do need a tiling affect for this functionality.

You should be able to create a layer in each scene, set the zOrder to something large so that it overlays everything else, and set its isTouchEnabled attribute to NO. You can then add whatever you want to the layer, which could be your patterned image. To change the alpha, just set the opacity attribute of your image. The only issue that I can foresee is that the overlay might disable touch events for layers below it.

Related

Unity2D layering multiple canvas'

I have two canvas' set up for my project, one to act as a background and one to hold foreground UI elements. Originally they were set to world space, and I had no problems, but now I am optimizing my game, I must change the space so they adjust to mobile phones. How can I design the canvas' so that one acts in the background and the other in the foreground? I have tried changing the z-pos and other quick fixes I found online but none have worked.
Ok, you have background canvas, sprites and foreground canvas, and background canvas should be behind everything including sprites.
The idea is to render at first only background with one camera, and then render everything with another.
To do that, we should:
Add a layer for background canvas. Change layer of background canvas and children to that layer.
To add a layer, select any gameObject and in top of the inspector you will see:
Click on a dropdown list labeled "Layer" and select "Add Layer". Then create new layer and give it a name:
Select your background canvas and change layer for it and its children. When adding gameObjects, keep in mind that if you add them to background canvas, their layer must be the same as the layer of canvas, otherwise they will be rendered by the wrong camera.
Disable that layer in main camera's culling mask.
Now the camera should no longer render background UI, and it will disappear in the game view.
Add a camera for rendering background UI.
Cameras with higher depth render on top of those with lower depth, so we should set its depth to less than depth of main camera. We should also set its culling mask to only layer for background UI, otherwise all objects on scene will be rendered twice. Copy other setting from main camera. Set main camera's clear mode to Don't Clear or Depth Only to prevent it from erasing background.
Set mode of the background canvas to Screen Space - Camera and drag newly created camera into field "Render Camera" there.
It should work now.

Unity3D - Set a (foreground) UI layer which ignores mouse clicks?

I'm currently writing up a UI-Centric game, and I've added a small image overlay over some elements on screen. However, the problem is that now I can't click any buttons behind this overlay image, regardless of transparency etc.
Just to chance it, I set up a new layer called "noUIclick" and set it to ignore every other layer under physics settings - long shot I know, but no dice. Tried also simply swapping to 3D view and moving the overlay image back on the z-axis.
Is there any easy way to set a layer for UI components which will entirely ignore/allow for passthrough of mouseclicks onto the buttons in the background?
On the Image component, uncheck raycastTarget.

How to make a hole in an image iphone

I have a game that players place their pieces on the screen then press set. I am using cocos 2d to build the iphone app. It is kind of like hide and seek. I then overlay a background on top of all of that. I want to be able to tap on the screen and create a hole in my background at that spot so that I can see through it. I know I can just create a giant image with a hole in it and move it around, but my background can only be a color it can't be an image. How should I go about doing this.
Instead of trying to see "through" the overlay, place the "background" image on top in circles. Map the screen coordinates on top of the "background" image, then extract a circular region from that image to place on the screen. The biggest challenge would be capturing a circular region from your bitmap. I'm not too familiar with cocos2d, but there should be a library you can use for it.

How to draw a light effect over a texture on iPhone using UIKit/Quartz

I have a scene with a background image (a lit room), and a black image (shadow) over that. I need to be able to move my finger over the background and reveal some parts of the scene, simulating a dim light source in a dark room.
My current approach was to generate a mask depending on the position of the touch, and then applying that mask to the shadow image. The problem is I'm generating a new mask and applying it every time I receive a touch event. It's a large image (800x600) and this causes the performance to go down and it increases a lot the memory usage, eventually crashing the game (I think I don't have any memory leaks, but that's not warrantied... anyway the performance itself isn't acceptable).
Can anyone think of a better approach (which doesn't involve using OpenGL ES -- that's not an option in this project) to do this?
To go with my comments above.
Maybe to get around the different shadow levels you could also have a grid of views (squares) between the image and the shadow view. each grid square has a different alpha opacity and when the spot is over a grid square, the grid square's alpha opacity changes to 0. when the spot moves off the grid square it's alpha opacity changes back to it's default.
Without more information it is a little difficult to know whether this approach will work in your case but what you could do is generate a single mask image, say, a radial alpha gradient and then apply an affine transform to it to shape it according to the touches. This can be used to simulate a torch/flashlight beam.
I would try this: use one view with a custom drawRect implemetation: first draw the shadow image (in grayscale) then a bright spot image in white an alpha. And finally the background image in a 'multiply' blend mode.
Just a thought, does the shadow has to be an image? Perhaps you could simply fill the shadow layer with a color and mask it then? This way the memory usage should be less and the effect should be nearly identical (if not exactly the same).
There is no reason to generate a new mask on every touch move. Instead, let the mask be initialized once and manipulate it (reset it's frame) as needed upon touch events.

Recreating streetview effect in my own iPhone App

My app allows you too "look" around a room in every similar manner to how you can "look" around a street when you are in streetview in the Maps application. Does anyone know of a simple way to recreate this effect?
I do have an image (like the streetview image) that I would like users to look around in.
Some ideas I have:
1) Put the image in a scroll view and let users pan and zoom. This doesn't seem like it would have the same effect as when you pan around the streetview, objects near the edges stretch to give you a "lens" type effect.
2) Apply a transform to the image before drawing it in a scroll view, and reapply the transform during scrolling. This transform would create the lens effect on the currently viewed part of the image.
3) Use open GL to create a hollow sphere and apply the image as a texture on the inside of the sphere.
doesn't seem like it would work
seems like my best option but I don't know what transform to use in quartz to create this effect. I like this though because it uses a scroll view and I don't have to recreate the panning, flicking and pinching code.
seems like overkill and too much work
Any ideas?