Error loading textures using Spritekit and Texture Packer - iphone

I am using SpriteKit and Texture Packer. I have a small sequence of animation. I was able to load certain images such as background and logos. But when I try to load the texture, which has an animation sequence using -
SKSpriteNode *char1 = [SKSpriteNode spriteNodeWithTexture:TEST_TEX_CHARACTER01];
It says SKTexture:Error loading image resource: "character01".
Please help me out!

Texture Packer creates a header file when you tell it you are using SpriteKit. I came across the same issue recently, although it worked just fine in a previous game. Everything appears to be correct in the plist, header and atlas.
I will edit my answer with a solution when I find one.
EDIT:
This turned out to be pretty simple. If you have any images with #2x in the name, change the name to a plain file name (e.g. ship#2x.png needs to be ship.png).
With that change to any files that need it and re-publishing your atlas from Texture Packer you should be able to use the convenience macro name from the header, e.g.
SKSpriteNode *ship = [SKSpriteNode spriteNodeWithTexture:ARTWORK_TEX_SHIP];

Related

Unity3d Resources.LoadAll<Sprite> empty array

In my resources folder structure I have myself a file, now in the unity editor this file is a Texture Type Sprite (2D and UI), now when I attempt to run this code in one of my scripts
var icons = Resources.LoadAll<Sprite>("Images/BuffIcons");
My icons variable is empty, now if I change the line above to
var icons = Resources.LoadAll("Images/BuffIcons");
It comes back with an array which has a Texture2D and then multiple Sprite objects. Now why can't I cast the objects to a Sprite?
Also just for your information the Sprite (2D and UI) is a Multiple sprite so this sprite in total has like 42 different sprites. It seems to me the sprite which holds all the other sprites is classed as a Texture2D and then all the sprites inside of the Texture2D are Sprites. How can I just tell the Resources.LoadAll to load the sprites?
So this is a really silly answer however I'm not going to delete this question because around the web I have seen this question in a view places and all the answer's didn't work for me so. Here is my fix :D
Basically I have a Sprite (2D and UI) file in Assets/Resources/Images/BuffIcons, in my code I have this line
BuffIconSprites = Resources.LoadAll<Sprite>("Images/BuffIcons");
Basically all I had to do was simply close Unity and re-open it, it seems if you create the sprite asset which contains multiple sprites you need to close and reopen Unity, I think this is something to do with the solution file which is constantly updated when stuff changing in your Unity file.
P.S. as you can see the line of code I provided hasn't changed. So I'm 100% sure this problem is something to do with the Unity solution

Unexpected sprite tearing?

I making a 2d game and I am having some very random problems... My sprites are not displaying as they should be. Below is a screen shot of what I see when I run my game. This bug is present in the game window and the scene window, both when the game is running and not running. And the glitch is not because of the tiles being offset (The background is made up of tiles), if you look closely the player sprite is also glitched up. I have tried restarting unity and my computer, one of which has worked. I have been having this problem ever since i started using tilesets (using one PNG image and cropping out smaller sprites by setting the sprite mode to multiple, instad of using just one PNG image where there is only one sprite and the sprite mode is singular). How do I fix this? (BTW I am using Oryx's lo-fi fantasy and sci-fi sprites at www.oryxdesignlab.com)
This happend when your atlas is not sliced correctly. When you making 2D game there are several important things about sprites.
Set Filter Mode to Point
Set Fromat to 16 bit or TrueColor (in special cases)
Make sure that your atlas is sliced properly.
Edit:
Adjust "Max Size" - make sure is value represents number equal or bigger than spritesheet size
The best way in sliceing atlas in Sprite Editor is NOT to use automatic. I got glithes like that in my project too and those steps can eliminate them.
Have a look at your Sprite in the Sprite Editor. I think you can get to it by double clicking.
Your sprites will have sort of boxes around them to identify each individual sprite (if you set your texture to multiple). One of these boxes will not have sliced correctly, and will have overlapped into another sprite, hence why you're seeing what looks like the arm of another sprite in your picture :)

Trying to change Sprite image but no luck... What am I doing wrong?

this is driving me crazy. I'm working with Unity3d ver5 and have a scene that has a MainCamera at (0,0,-10) and a sprite called BackGround at (0,0,0). Both rotation and scale are (0,0,0) & (1,1,1) respectively. I have a very simple script called BackGround.js attached to the sprite it is a simple and straight forward:
function Start () {
var spr = GetComponent.<SpriteRenderer>();
spr.sprite = Resources.Load("bg") as Sprite;
Debug.Log(spr.sprite.ToString)
}
bg is a PNG image located in the Assets folder root.
What I want to achieve is to be able to chose a certain image to use as the BackGround sprite using this script, i.e. I start the BackGround sprite with the Sprite : None, then load the image using the script.
This is not working and I end up with a blue empty screen when I run it. More over the Debug.Log is showing the following:
NullReferenceException: A null value was found where an object instance was required.
What am I doing wrong here? Thanks.
For your resource to be loaded via Resources.Load your asset needs to be placed under a folder named Resources, it isn't mandatory for the folder's parent to be Assets but it needs to be named Resources.
You may have multiple Resources folder under your project and Unity will look in all of them to try to locate your resource. This is important because you may have the same path for a resource when calling Resources.Load but multiple resources that match it, so you need to be careful.
That being said you should create a folder named Resources and add your png there.
I've found the solution for that.
The:
spr.sprite = Resources.Load("bg") as Sprite;
should be changed to:
spr.sprite = Resources.Load("bg", typeof(Sprite)) as Sprite;
Now working like charm!

Is there a way to build asset bundle that exclude texture2d from an image?

In unity 4.x, I can archive this because I can select my resource type directly as Sprite variable before putting it into the bundle via BuildAssetBundle. However, in Unity 5.x, I need to put the name in the Editor can I cannot choose my resource type as Sprite only in the Editor. When I make the bundle, bundle will have both Texture2D and Sprite which I only want Sprite to save the memory and disk space. The bundle will exclude Texture2D only if I create the bundle from Prefab not the image itself but I want only the raw image. What should I do?
As clarification for future readers, I'm taking into account your other question, and that the reason you want to exclude the original texture is because you use the atlas that the Sprite Packer generates.
Short answer: Just don't add the textures in any bundle and let everything be taken care of in the shadows. For each bundle, any sprite or atlas needed will be referenced by the object that needs it, so they will be included.
Long, but insightful answer: First, let's compare the two AssetBundle buidling pipelines:
In Unity 4.X, to create an AssetBundle you chose the assets you wanted to bundle together. You would then call BuildPipeline.BuildAssetBundle, using the BuildAssetBundleOptions to optionally CollectDependencies or include the CompleteAssets.
In Unity 5.X, the old system is flagged as obsolete but still supported, though according to this post it might not be in the future. Adding to that, the new system will be further developed, so using the old one should be avoided.
The new pipeline is now integrated into the AssetImporter. Now, when building a bundle, the behaviour is that of having both CollectDependencies and CompleteAssets enabled in the old method.
Sprites are generated by the texture's import settings, and don't have any AssetImporter of their own. The texture atlases created by the Sprite Packer are cached in \Library\AtlasCache, so they don't have AssetImporters either.
This means that individual sprites and packed atlases can only be included in a bundle when they are dependencies of another included asset. As said by someone working on it.
If you add a texture to a pack, all the sprites it created will be added (this is the CompleteAssets behaviour), but of course this will add the texture itself too.
If a sprite is added, the texture it uses will be added too (CollectDependencies behaviour), regardless of if it's a texture file in the project or a Sprite Packer atlas.
The bottom line is that you don't want to add the texture. At all. Never. The original textures are for editor work only. Instead, you need to do add to the bundle anything else that references the sprites, but not the texture itself.
The hackiest way to do that is using a prefab with a script like this:
public class SpriteReferences : UnityEngine.MonoBehaviour {
public UnityEngine.Sprite[] sprites;
}
But chances are that among all the things you want to add to the bundle (prefabs, scenes, scriptableObjects) the sprites you need are already referenced, so they will be added, and in turn any needed atlas will be added too. And everything done without adding the original texture.
Beware: If a single object in an asset bundle references a sprite, its whole atlas will be added. Keep your packing tags organized, they should roughly correspond to the bundles you make.
This issue has been fixed by Unity in Patch 5.1.2p1. You don't need to do anything fancy at all. Unity will do it all for you. Just follow the simple build asset bundle step and that's it. :)

How do I change the sprite shape within this open source iPhone game?

I downloaded the open source example game iSpacies and am trying to understand its design.
For example, how would you go about changing the alien image into a 'V' shape and the the fighter object image into a shape like this: '^'?
Mmmm this code seems using some king of game Engine.
But for your question, see the ispacies.png png file. It contains all enemies image :-)
But if you modify the image you will (probably) need to change some kind of variable in the program (I didn't find where).
But he's using OpenGL ES to do animations. You can to try using Core Animation with UIViewImage and CALayer :-)
Good Luck !