Setting up a new Animation to an element in a layout [RESOLVED]

I just typed a bunch of blah blah about my problem but I think I figured it out by looking at the layout ninja example.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
        -- new group
        groups['actors'] = display.newGroup()
        groups['layout0']:insert(groups['actors'])
 
        -- new sprite
        elements.ninja = _spriteFactory:newSpriteGroup("ninja run")
        group = elements.ninja
        groups['ninja'] = group
        group.elementName = 'ninja'
        group.libraryName = "ninja run"
        groups['actors']:insert(group)
        group.x = 77
        group.y = 320
        dimensions['ninja'] = {width = 137, height = 149}

Hi eric,

group.libraryName is just metadata. You don't need to touch it. It's there to tell you what the element was initialized as. If you want to switch animations, for the spriteGroup you just call play with the new animation. Not sure what you're doing on line 6, but to switch between animation you call play.

If you don't actually have a sprite with a name "SpriteAnim1, SpriteAnim2, SpriteAnim3, SpriteAnim4" the call will fail.

I usually just go layout.elements.mySprite:play('SpriteAnim1'). And to play a new animation layout.elements.mySprite:play('SpriteAnim2').

With the Spriteloq API you don't have to define what animations a SpriteGroup can play it can play / prepare any asset available in the spritesheets loaded into the SpriteFactory.

e.g.

1
2
3
4
5
6
7
8
9
-- sheet1 contains SpriteAnim1, SpriteAnim2
-- sheet2 contains SpriteAnim3, SpriteAnim4
 
local sf = require('loq_sprite').newFactory('sheet1', 'sheet2')  --load both sheets
local sg1 = sf:newSpriteGroup('SpriteAnim1')
sg1:play()
 
-- elsewhere
sg1:play('SpriteAnim4')

It does. I started completely from scratch to understand the layout.lua better by giving everything an original name. This helped me GREATLY. I also now think I understand how Ninja can control Ninja Jump, Ninja Run etc.

Without scaring anyone new away to SpriteLoq here is what I did to visualize what exactly was going on...

http://www.erickinkead.com/code/spriteloq/myLayoutDiagram.jpg

This makes so much more sense now versus trying to figure this out with a Sprite1 Movie Clip, jn a Sprite1 Layer, With a Sprite1 Label.

So according to this, I can understand how I can animate layout.elements.mySprite1:play('SpriteAnim1')

If you look at my diagram you can see that I created a mySprite with the label 'firstSprite'. So therefore I would

layout.elements.firstSprite:play("MySprite1 Anim1") ?

[EDIT]

A-HA! I see what is going on! Layout is requiring that MySprite1 has an animation called MySprite1. That is why I was having so much trouble loading Anim1, Anim2, Anim3 into layout.elements.firstSprite:play("MySprite1 Anim1"). It is assuming that the first animation it starts with will be the one named after it. So I just made a .swf containg one of the frames of Anim 1 (and since Aliasing is working doesn't matter much) I called it MySprite1 and WALLA! I can now trigger off my other animations with afferent names through layout!

my anims are actually called MySprite1 Anim1 because of the splits thing, but I understand that is one label.

Now to create secondSprite:play("MySprite2 Anim") and its off to the races.

Yup your diagram is connecting everything correctly even if it is scary at first glance. :) Symbol instance names map to SpriteGroups in the layout.elements table.

Yea, I don't want anyone new above to misrepresent that as SpriteLoq being difficult! I am Arts, Designer, THEN programmer... I need things very visual.

Hey did you read above? About Layout? Assuming that newSpriteGroup has a sprite animation named after it? makes sense though, its gotta start somewhere.

this is resolved.

views:1477 update:2012/1/1 13:29:50
corona forums © 2003-2011