I need to be able to load images from URLs. When a user loads one of their projects, I use AJAX and php to retrieve:
# of parts|partid1|partURL1|partid2|parturl2| etc...
Thanks to the chrome debugging tip, I learned how to avoid the cross-domain issue, temporarily.
I'm not sure how to approach this next step:
At first I tried attaching a single tempSprite to the layout and using System>Create Object, then calling Load image from URL on (what I think is) a new copy of the sprite? The result was all the sprites ended up changing image, not just the newly created one.
Next, just to see if it would work, I created two separate tempsprite1 and tempsprite2 sprites and attached them to the layout/layer. This approach works (as far as each sprite loading a different image/url), but so far, all I can see to do is set values (positions, scaling, custom zindex, rotations, etc) through actions attached to each individual sprite. This route means I would have to pre-define a large number of sprites and value setting actions to each sprite. Should I expand on the app (say color offsets etc) I would have to go back and edit every tempspriteX's 'set' actions. I tried functions as well, but to no avail.
I tried using Families. I tried creating a new Family "parts" where parts contained a tempSprite sprite, but this had the same problem as the first approach, everything was the same image.
I'm coming/converting from pure actionscript3 where I just create a loop that defined a temporary sprite each iteration, set its image and attributes, then pushed it to an array of sprites and continued until there were no more images from the php/url request. I do not know if anything like this is possible in C2.
I have searched the forums a few times with no success. C2 is great. I've learned a lot in the few days I have used it. I'm amazed by the # of sprites I can manipulate on a desktop/html5 app compared to Flash. Even if I cannot find a good solution to this particular problem, I'm already happy to have paid for it.
Develop games in your browser. Powerful, performant & highly capable.
Sprite instances share the same set of image so if you replace an image it will be replaced for all other instances. One method that's often used is to just add a lot of empty animation frames for the number of images you might use during runtime. Just set the animation frame before the load from url action and be sure the animation speed is 0.
That being said tiledbg and all these third party plugins can have a unique image per instance.
http://www.scirra.com/forum/plugin-canv ... 46006.html
^ I may be remembering wrong about this one.
Looks like the animation frame solution will work for me. It has the 'on image url loaded' event that I seem to need to use to adjust height/width.
I tried paster, which looks incredibly useful for another aspect of what I want to make, but I could never get the size/height/width to update. Paster does not seem to have an 'on image url loaded,' so setting it's size right after the action to load image from url seems to operate on an empty Paster object. Or I'm just very tired.