Cocos2d: Invert a texture, display the mirror image? - ios

How could I invert a Texture created from an image (I mean display the mirror image), if I have for example a kid rising his left hand I'll get a kid rising his right hand. Thank you.

I found the solution
aSprite.flipX = YES;

Related

SpriteKit sktilemapnode vertical line glitch

I am making a 2d platformer and I decided to use multiple tilemapnodes as my backgrounds. Even with 1 tile map, I get these vertical or horizontal lines that appear and disappear when I'm moving the player around the screen. See image below:
My tiles are 256x256 and I'm storing them in a tileset sks file. Not exactly sure why I'm getting this or how to get rid of this and it is quite annoying. Wondering if others experience this as well.
Considering to not use the tile maps, but I would prefer to use them if I can.
Thanks for any help with this!!!
I had the same issue and was able to solve it by "extruding" the tiled image a couple pixels. This provides a little cushion of pixels to use when the floating point issue occurs instead of displaying nothing (hence the gap). This video sums it up pretty well.
Unity: extruding tile map images
If you're using TexturePacker to generate your sprite atlas' there is an option to add this automatically without having to do it to your tile images yourself.
Hope that helps!
Sort of like the "extruding" suggested by #cheaze, I simply make the tile size in the drawing code a tiny amount larger than the required tile size. This means the assets themselves do not have to be changed.
Eg. if you assets are sized 256 x 256 and all of your calculations are based on that; draw the textures as 256.02 x 256.02 pixels in size:
[SKSpriteNode spriteNodeWithTexture:texture size:CGSizeMake(256.02, 256.02)];
Only adding .02 pixel per side will overlap your tiles automatically and remove the line glitches, depending on your camera speed and frame rate.
If the problem is really bad, you can even go so far as to add half a pixel (+0.5) or an entire pixel to remove the glitches, yet the user will not be able to see the difference. (Since a one pixel difference on a retina screen is hard to distinguish).

Tiling images with 3D perspective

I'm not quite sure if the captioned is my problem. I will explain the challenge first and then probably you can advise whether I'm doing something fundamentally wrong.
I'm creating an iOS application which will let users drag and drop floor and wall tiles on a room (pre-selected room images only) and can see how that tile will look when laid on the room. I have the tile images and the room image and I've defined hotspots (where tile need to be replaced) relative to the room image.
On my room simulator view, I have a UIImageView which holds the room image and certain parts of that image are made transparent. I also have smaller UIImageViews which I have put on top of the room image.
When the user drags and drops the tile image on the smaller image views, I'm creating an UIImage using the method
[sourceImage resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeTile];
which gives me a tiled image and that image is then set as the source of the smaller image view.
This logic is working but I'm not getting the desired effect. If the user is dropping the tile on the floor, the final image looks like the floor and the walls are on different planes. Please checkout the image below
The view on the right has 2 images, the room images with transparency and a smaller image where you see the floor tile now.
So my question is, can I tile images with some sort of 3D perspective ? I'm afraid I'm not that good in 3D transformations and the 3d matrices looks greek to me.
I guess the problem is mostly because of the angle in which we are viewing the resultant image and the floor tile images should be tiled with that in mind. Or in other words, the size of the tile on the back side of the room should be smaller than the size of the tile in the front side. I may be wrong.
Any help would be greatly appreciated.
A bit late, but what you need is "CIPerspectiveTile":
https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CoreImageFilterReference/Reference/reference.html#//apple_ref/doc/filter/ci/CIPerspectiveTile
You'll need to create a CIFilter, set the input values (5 - image, 4 perspective points), then create a CIImage, then draw that image out. There are various ways to do so. You can do something as simple as:
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef tiledImage = [context createCGImageFromCIImage:myCIImageWithPerspective fromRect:boundingRect];

OpenGL ES IOS Texture 2D drawing upside down

I am writing a small game (it is 2d) in IOS using Opengl as a way to get comfortable with opengl. I am using the Texture2D class from the CrashLanding demo. I am using this to generate text for the score. When the text is drawn it is upside down. In the code there is comments about the texture being loaded upside down but I can not find a way to render it the correct way. Any help would be greatly appreciated.
OpenGL and your image loading code do not agree on where the origin is. OpenGL starts in the lower left hand corner, while your picture starts in the upper right hand corner. You can apply a transform to the picture in your app like the CrashLanding demo does. Or even simpler pre flip the image in an editing program such as Photoshop. This will work if your image will only be used as an OpenGL texture in this app. If you need to display this same picture elsewhere you'll need to keep a non flipped version, or figure out how to apply the transform.

How to select a triangle in XNA?

I have a triangle with a transparent background (png image) I want its color to change when selecting it.
The point is that the color should change only when touching the non-transparent part of the image.
This should be working when the image is scaled..
Any ideas please?
Thanks...
Since you do not know the exact size/shape of the triangle, you'll need to use Per-Pixel collision detection. The App Hub has a tutorial for that. It even works with scaled/rotated objects.
Hope it helps!

Xna game development - Game background issue

Im starting with XNA and i need an advice about the following.
I have a .jpg file with my space ship game background with the following size:
width: 5000px
height: 4800px
When i try to load the texture i get the following error:
Texture width or height is larger than the device supports
What is the most used technique to move the background at the same time that your ship is moving?
Thanks a lot.
Kind Regards.
Josema.
One way would be to separate your image into smaller tiles and draw the visible ones.
However this technique suffers from a problem when bilinear sampling is used, because the colors bleeds from the one side of the texture to the other. You can probably compensate by disabling texture WRAP sampling or by grabbing a single of pixels from the tiles next to.
For example if you want 256x256 textures, you would only display 255x255 tiles, because one line (right and bottom) is a copy from the tiles next to it.
Hope it makes sense, otherwise I'll have to paint a picture :-)
The texture limit is determined by graphics card, I believe.
You want to break the texture down to smaller images.
Try something like this. He's tiling a simple 40x40, but you might use it a a guideline on how to tile yours.
http://forums.xna.com/forums/p/19835/103704.aspx
To move the background at the same time that your ship is moving you can implement a camera.
The following links might help-
http://adambruenderman.wordpress.com/2011/04/05/create-a-2d-camera-in-xna-gs-4-0/
http://www.dreamincode.net/forums/topic/237979-2d-camera-in-xna/

Resources