static int lnewproxy(lua_State *L) { static struct pack_part part = { { NULL, // mat 0xffffffff, // color 0, // additive PROGRAM_DEFAULT, 0, // _dummy }, // trans 0, // component_id 0, // touchable }; static struct pack_frame frame = { &part, 1, // n 0, // _dummy }; static struct pack_action action = { NULL, // name 1, // number 0, // start_frame }; static struct pack_animation ani = { &frame, &action, 1, // frame_number 1, // action_number 1, // component_number 0, // _dummy {{ "proxy", // name 0, // id 0, // _dummy }}, }; struct sprite * s = lua_newuserdata(L, sizeof(struct sprite)); lua_newtable(L); lua_setuservalue(L, -2); s->parent = NULL; s->s.ani = &ani; s->t.mat = NULL; s->t.color = 0xffffffff; s->t.additive = 0; s->t.program = PROGRAM_DEFAULT; s->message = false; s->visible = true; s->multimount = true; s->name = NULL; s->id = 0; s->type = TYPE_ANIMATION; s->start_frame = 0; s->total_frame = 0; s->frame = 0; s->data.children[0] = NULL; sprite_action(s, NULL); return 1; }
static int lsetaction(lua_State *L) { struct sprite * s = self(L); const char * name = lua_tostring(L,2); sprite_action(s, name); return 0; }
void sprite_init(struct sprite * s, struct sprite_pack * pack, int id, int sz) { if (id < 0 || id >= pack->n) return; s->parent = NULL; s->t.mat = NULL; s->t.color = 0xffffffff; s->t.additive = 0; s->t.program = PROGRAM_DEFAULT; s->message = false; s->visible = true; s->multimount = false; s->name = NULL; s->id = id; s->type = pack->type[id]; s->material = NULL; if (s->type == TYPE_ANIMATION) { struct pack_animation * ani = (struct pack_animation *)pack->data[id]; s->s.ani = ani; s->frame = 0; sprite_action(s, NULL); int i; int n = ani->component_number; assert(sz >= sizeof(struct sprite) + (n - 1) * sizeof(struct sprite *)); for (i=0; i<n ;i++) { s->data.children[i] = NULL; } } else { s->s.pic = (struct pack_picture *)pack->data[id]; s->start_frame = 0; s->total_frame = 0; s->frame = 0; memset(&s->data, 0, sizeof(s->data)); assert(sz >= sizeof(struct sprite) - sizeof(struct sprite *)); if (s->type == TYPE_PANNEL) { struct pack_pannel * pp = (struct pack_pannel *)pack->data[id]; s->data.scissor = pp->scissor; } } }