I have been trying to create an Animation Sprite Clip from a programmatically created sprite. The problem is that the animation sprite clip requires an asset id to create the animation. The sprite component has no name attribute so I cannot search with asset.find(). Setting the sprite after creating the clip is just ignored by the engine.
I tried load/add the asset in case it wasn’t done by default. Got errors doing that so I assume that it is.
And with the off chance that shoving the sprite into the slot would work, it put the sprite into the sprite asset spot. Does not render anything. and the _Sprite is null. The only way I can assume that it works is with the asset Id which I cannot seem to get.
I did create an animation clip and got it running without a programmatically created sprite but doesnt seem to work with the extra step.
For completeness sake error messages for add, and load.
add:
load:
Example json values:
"frame": {"x":0,"y":0,"w":201,"h":324},
"rotated": false,
"trimmed": true,
"spriteSourceSize": {"x":704,"y":351,"w":1149,"h":675},
"sourceSize": {"w":1149,"h":675}
Currently have:
var piv = new pc.Vec2(0.5, 0.5);
var Atlas = new pc.TextureAtlas();
Atlas.texture = this.SpriteSheet;
var i = 0;
Atlas.frames = {};
var FrameKeys = [];
frames.forEach(function(element)
{
FrameKeys.push(i.toString());
Atlas.setFrame(FrameKeys[i],
{
//element.frame is from a json file. Can just fill in any set of values here to make it work.
rect: new pc.Vec4(element.frame.x, element.frame.y, element.frame.w, element.frame.h),
pivot: piv,
border: new pc.Vec4(5, 5, 5, 5)// Left as example since wasnt 100% certain what it does for me.
});
i++;
});
var Sprite = new pc.Sprite(this.app.graphicsDevice,
{
pixelsPerUnit: 1,
renderMode: "SPRITE_RENDERMODE_SIMPLE", //Doesn't seem to exist on pre-generated sprites.
atlas: Atlas,
frameKeys: FrameKeys
});
console.log(Sprite);
var clip = new pc.SpriteAnimationClip(this.Test.sprite, {
name: "g",
fps: 2,
loop: true,
spriteAsset: Sprite
});
clip.sprite = Sprite;
this.Test.sprite.addClip(clip);
this.Test.sprite.play("g");