Mercurial > MadButterfly
annotate examples/dynamic/hello.c @ 453:84ce2d4a8c3f
Change interface of sprite loader.
- Users can set a path where sprites should be loaded from.
- Users must pass a module root to MBApp_Init() to specify path
for loading sprites.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 05 Aug 2009 19:34:59 +0800 |
parents | 31b6633e3538 |
children | 9b8dda201ccb |
rev | line source |
---|---|
247 | 1 /*! \file |
2 * | |
3 * svg2code_ex is an example that show programmers how to create a | |
4 * menu with MadButterfly. | |
5 * | |
6 */ | |
7 #include <stdio.h> | |
8 #include <mb.h> | |
9 #include <string.h> | |
387
433fa83d16f9
Corrected build dependence - able to build in Ubuntu Intrepid
Ben Lau <xbenlau@gmail.com>
parents:
247
diff
changeset
|
10 //#include "menu.h" |
247 | 11 #include "mbapp.h" |
12 | |
13 | |
14 MBApp *myApp; | |
15 | |
16 typedef struct { | |
17 shape_t *rect; | |
18 co_aix orx,ory; | |
19 int start_x,start_y; | |
20 observer_t *obs1,*obs2; | |
21 int currentscene; | |
22 }MyAppData; | |
23 | |
24 | |
25 void switch_scene(const mb_timeval_t *tmo, const mb_timeval_t *now,void *arg) | |
26 { | |
27 MyAppData *en = MBAPP_DATA((MBApp *)arg,MyAppData ); | |
28 mb_timeval_t timer,interval; | |
29 | |
30 | |
31 get_now(&timer); | |
32 MB_TIMEVAL_SET(&interval, 1 ,0); | |
33 MB_TIMEVAL_ADD(&timer, &interval); | |
34 mb_tman_timeout( MBApp_getTimer(myApp), &timer, switch_scene, myApp); | |
35 | |
36 en->currentscene = (en->currentscene + 1) % 2; | |
37 printf("switch to scene %d\n", en->currentscene + 1); | |
38 MB_SPRITE_GOTO_SCENE(myApp->rootsprite,en->currentscene + 1); | |
39 } | |
40 | |
41 int main(int argc, char * const argv[]) { | |
42 subject_t *subject; | |
43 mb_button_t *b; | |
44 mb_obj_t *button; | |
45 MyAppData data; | |
46 mb_timeval_t tmo,interval; | |
47 | |
453
84ce2d4a8c3f
Change interface of sprite loader.
Thinker K.F. Li <thinker@branda.to>
parents:
399
diff
changeset
|
48 if (argc > 1) |
84ce2d4a8c3f
Change interface of sprite loader.
Thinker K.F. Li <thinker@branda.to>
parents:
399
diff
changeset
|
49 myApp = MBApp_Init(argv[1], ""); |
247 | 50 else |
453
84ce2d4a8c3f
Change interface of sprite loader.
Thinker K.F. Li <thinker@branda.to>
parents:
399
diff
changeset
|
51 myApp = MBApp_Init("scene", ".libs"); |
247 | 52 data.currentscene=0; |
53 MBApp_setData(myApp,&data); | |
54 //b = mb_button_new(myApp, myApp->rootsprite, "btn"); | |
55 //mb_button_add_onClick(b, test,NULL); | |
56 get_now(&tmo); | |
57 MB_TIMEVAL_SET(&interval, 1 ,0); | |
58 mb_tman_timeout( MBApp_getTimer(myApp), &tmo, switch_scene, myApp); | |
59 | |
60 | |
61 MBApp_loop(myApp); | |
62 | |
63 return 0; | |
64 } | |
65 | |
66 /* vim: set ts=4 */ |