Basically i have an array of Sprites to be loaded and removed one by one in an order.
I have a list of animal names in an array like
const NSString *Animal1[30] = {#"Lion .png",#"Zebra .png",...........
To load a sprite i use the following code
image[i]= [Sprite spriteWithFile: [NSString stringWithFormat:#"%#",Animal1[i]]];
image[i].position = ccp( 240,180 );
[self addChild: image[i]];
Then to remove the sprite after use I use the following code
[self removeChild:image[i] cleanup:YES];
What happens when i run the code in simulator is the sprite loads one after other till 20th animal. After the 20th animals the application crashes.
I dont know what is the problem.If i have the array less than 20 it works fine but when it exceed the application crashes.
Can anyone plz help to resolve the issue.
If it works for the first 20, it sounds like you may have a bad image or an erroneous filename for that 21st image. If you try to create a sprite from an unsupported or nonexistent image, then you'll get a crash.
Check and make sure all the filenames listed are actually inside your package (check case, too, since they're case sensitive!). Make sure the filenames match exactly - in the code sample you pasted above, it looks like there are spaces in the titles.
If the files are all there, make sure you didn't save one of them as a Photoshop document instead of as a .png or something. Even if the filename ends in .png, it doesn't mean that it was saved in that format.
From your description of the problem it could even be a bad index and you're just incrementing out of bounds or something. The best way to clear it up is to do some basic debugging.
place the last item in the middle of
the array. Does it still blow up on
the last one or on the same entry no
mater what position it's in?
remove the offending item to see if
the code works without it
trace thru the code and see the
entry point where it's blowing up,
check your stack trace, etc.
To verify all your files are ok try to load each one manually not using an array like(put a break point on each line and use Build & Debug):
(pseudo code)
add the lion sprite
add the tiger sprite
add the bear sprite
...etc...
If that works then test your array by not using a loop to load the sprites, load each one by calling it's index like(put a break point on each line and use Build & Debug):
(pseudo code)
add image[1]
add image[2]
add image[3]
...etc...
Then if that works fine I would setup your sprites into and array of sprites like:
(pseudo code)
create the sprite with image[i]
add the sprite to spriteArray
---repeat for each sprite---
Then do another loop to add the sprites to the layer like:
CGSize size = [[CCDirector sharedDirector] winSize];
for CCSprite *aSprite in SpriteArray {
aSprite.position = ccp((size.width - (aSprite.contentSize.width / 2)), (aSprite.contentSize.height / 2)); //positions the sprite to the lower right corner
[self addChild aSprite];
}
I like to put my sprites in an array, that way it's easier to just traverse the array when I need to work with them. Also, instead of using absolute coordinates, I like to use coordinates that are relative to the size of the window and the size of the sprite. By positioning them this way, it will convert the coordinates no matter what type of display or orientation or sprite size you are working with.
Hope this helps!
Related
added a tilemap to the scene, and for some reason there are two of them, there is only one in the inspector, but if you move the coordinates, then there will be another map on the background and for some reason the character was also cloned, what could be the problem?
I thought maybe the link to the prefab was wrong or it was added to the stage in the wrong way, but everything seems to be right
int MapNumber = GameState.currentRoom;
Tilemap map = GridsMap[MapNumber].GetComponent<Tilemap>();
CurrentMap = Instantiate(map);
CurrentMap.transform.position = Anchor;
I am using Leafletjs in Nuxt by using a NPM package. Thus I am using a wrapper to use Leafletjs in Nuxt.
The problem I have now is with this piece of code:
<l-map
:zoom="4"
:center="[0, 0]"
:max-zoom="6"
:min-zoom="3"
:options="{ attributionControl: false }"
#mousedown="mouseMovClick($event)"
>
<l-circle
:lat-lng="[markerPosition.lat, markerPosition.lng]"
:radius="100000"
color="rgba(76, 211, 40, 0.9)"
:fill="false"
:weight="2"
/>
<l-circle
:lat-lng="[markerPosition.lat, markerPosition.lng]"
:radius="200000"
color="rgba(76, 211, 40, 0.9)"
:fill="false"
:weight="2"
/>
<l-circle
:lat-lng="[markerPosition.lat, markerPosition.lng]"
:radius="300000"
color="rgba(76, 211, 40, 0.9)"
:fill="false"
:weight="2"
/>
</l-map>
For each "circle" that I add, they obviously become bigger. But they also become more "egg" shaped for some reason that I do not understand.
Does anyone know what could be wrong or what could be causing this anomaly?
EDIT: Found out, well, I think that the circle is bending to the shape of the earth. In my case I do not want it to bend. It should always remain a perfect circle. Is that possible?
I added this to my code:
import { CRS } from 'leaflet'
And inside my setup:
const crs = CRS.Simple
This seems to be working, but now I end up with this error:
window is not defined
var requestFn = window.requestAnimationFrame ||
getPrefixed('RequestAnimationFrame') || timeoutDefer
EDIT: I got it working (will update my post soon), but the next problem now is that the image names have changed and thus the map does not load anymore.
I am using this script to make the tiles in Photoshop.
https://github.com/bramus/photoshop-google-maps-tile-cutter
I have no options/ influence for the names. So, when I do not set the CRS the names are correct i.e. 5/4/2.png but when I use CRS the names change to i.e. 5/4/-2.png and those do not exist.
I also tried https://github.com/libvips/build-win64-mxe/releases but that gives me a weird output where all tiles will be unsorted somehow.
vips.exe dzsave IMAGE_LOCATION FOLDER_LOCATION --layout google --background 0E0E0E --centre --suffix .png[Q=100]
I think I have to, somehow, have to make sure that the map only starts and ends within these folders:
1/1/1.png up to 1/24/64.png
2/*/*
3/*/*
4/*/*
5/*/*
6/1/1.png up to 6/24/64.png
where all numbers are positive never negative. The same applies to the image names. Always positive numbers never negatives. The above reassembles my directory structure after tiling the images.
Also, another thing that happend is when I refresh my map, the markers look like they are in place, but the map itself has moved away to the bottom right for some reason. No clue why it shifted.
I'm surfing lot in google and spending more time but couldn't find the solution.
I tried converting PNG to bytes[] then attaching but no solution I found.
I have two PNG file one is full of Props like Hair, Dresses, Hand Glow, etc,.. another is undressed character. How to implement to show Glow, Hair and Dressed up Character. Simply I planned to Drag and Drop, Drag the hair and drop on head of the character to show.
How could I merge part of PNG[Hair, Glow, Dress..] file and drop on another Part of PNG[Head. Hand, Body...] file.
Shall I split different PNG files like Hair part alone, Glow part alone, Dress part alone.
Which is best way to do this Please give some link or project for reference or give some idea theoretically
NOTE: This only in 2D[PNG images] not 3D characters or materials.
Please refer this image
You don't want to merge them, you want to make them overlap.
public class CharacterSprite:MonoBehaviour{
public Vector2 position;
public Item itemValue;
}
public enum Item{ None, Hat, Eyes, Mouth,...}
Your character would have a ItemController:
public class ItemController:MonoBehaviour
{
private CharacterSprite hat
public void SetItem(CharacterSprite shSp){
switch(shSp.itemValue){
case Item.Hat:
this.hat.gameObject.SetActive(false);
this.shSp.gameObject.SetActive(true);
this.hat = shSp;
break;
// other cases
}
}
}
This method would swap the current off and put the new one on.
But the layer on the SpriteRenderer is the important one there as you would expect the body to be 0, hair is 1 maybe eyes over the hair so 2 then the clothes and hats are 3 (maybe eyebrows are over hats, dunno), weapons should be seen over it all so 10 (this gives some leeway for other items in between).
I would consider this approach faster, safer and saving memory since you are keeping your sprites are they are and you are only overlapping them.
You can easily make unique sprites from your atlas using the SpriteEditor. You just need to make your sprite as multiple.
I am using the (really cool) WhirlyGlobe (https://code.google.com/p/whirlyglobe/) 3D globe display for iPhone in a new application. I can add labels at certain locations using the code shown below. I want to be able to go back and remove a label I added earlier. The Documentation (http://whirlyglobedocs.s3-website-us-east-1.amazonaws.com/html/interface_label_layer.html#ac17e1ec72e70eec416cb2cac833f46fa) shows a removeLabel method but I cannot seem to get it to work. I can add but not remove Labels. I tried looping through all subviews but cannot find these SimpleLabel instances. Can someone please help me understand how to remove a label? I haven't had much luck finding many examples. Thank you!
// Current position
float lat = [[values objectAtIndex:8] floatValue];
flaot lon = [[values objectAtIndex:9] floatValue];
// Create a SingleLabel at this Lat / Lon pair location
SingleLabel *interimLabel = [[[SingleLabel alloc] init] autorelease];
interimLabel.text = [NSString stringWithFormat:#"PRN %d",[[values objectAtIndex:1] intValue]];
[interimLabel setLoc:GeoCoord::CoordFromDegrees(lon, lat)];
[locationArray addObject:interimLabel];
[allLabels addObject:interimLabel];
When you add a single label or a group of labels to the label layer, you'll get back a SimpleIdentity. Keep that around somewhere. Then, when you want to delete the label (or group of labels) from the label layer, you pass back in that SimpleIdentity.
What's going on is this. WhirlyGlobe batches drawable data like a mofo. Your SingleLabel objects no longer exist as soon as the Label Layer has crunched them down into as few Drawables and it can get away with. So to refer to those labels, you have to keep around the unique ID.
Now if you want to delete these labels separately or individually change their appearances, then you've got to add them one by one. One label to one SimpleIdentity. Otherwise there's no way to refer to them individually.
For speed, I recommend grouping as many of them together as you can get away with. If that's just too complex for now, add them one by one and then make a note to come back. So when you say "Why isn't this running as fast as I'd like" you can then say "Ooooo, right."
I'm trying to work with a scroll view controller that needs to adjust it's contents based on user interaction -- specifically, by adding a 'done' button while the user is working with a UITextView, then removing it when they are done. The problem is making room for the button in question. What I'd like to do is...
control.layer.position.x-=50;
for every single control that is 'below' the one I'm working with. Unfortunately, that doesn't work. As far as I can tell, I'm going to have to do something more like...
control.layer.position=CGPointMake(newX, newY);
This creates a maintainability nightmare; instead of being able to rearrange buttons inside UIBuilder at will, I'm going to have to change their positions in the code as well. Unfortunately, no matter what variant of the first type of code I use, the result doesn't work; I'm informed that I need an lvalue to the left of the assign or that I'm trying to manipulate incompatible types.
It'll be more verbose than the -= solution, but why don't you just calculate newX and newY based on their old values?
e.g.
CGPoint oldPosition = control.layer.position;
control.layer.position = CGPointMake(oldPosition.x - 50, oldPosition.y);
The button comes with a center property, so:
button.center = CGPointMake(button.center.x - 50, button.center.y);
should do the trick