我现在的想法是这样的:
在程序主界面上显示一个小人,然后可以在程序中控制小人的动作。不用很复杂就是有基本的跑步走路和静止三种状态就可以。
我想是不是可以用表示几种不同状态的gif来表示,然后在程序中切换图片来更改显示的状态。
对gtk不很熟,这种方法是否可行,或者还有什么更好的方法,大家有什么好的建议?谢谢!
用gtk做跑步的动画
答案:1 悬赏:10
解决时间 2021-12-29 16:21
- 提问者网友:冰点阿弟
- 2021-12-29 03:39
最佳答案
- 二级知识专家网友:duile
- 2021-12-29 03:50
#include
#include
void on_running_clicked(GtkButton *button,gpointer image)
{
gtk_image_set_from_file(GTK_IMAGE(image),"running.gif");
}
void on_stop_clicked(GtkButton *button,gpointer image)
{
gtk_image_set_from_file(GTK_IMAGE(image),"stop.gif");
}
int main(int argc,char *argv[])
{
gtk_init (&argc, &argv);
GtkWidget *window,*image,*layout,*button_running,*button_stop;
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(window,300,200);
layout=gtk_layout_new(NULL,NULL);
image=gtk_image_new();
button_running=gtk_button_new_with_label("running");
button_stop=gtk_button_new_with_label("stop");
gtk_container_add(GTK_CONTAINER(window),layout);
gtk_container_add(GTK_CONTAINER(layout),image);
gtk_container_add(GTK_CONTAINER(layout),button_running);
gtk_container_add(GTK_CONTAINER(layout),button_stop);
gtk_layout_move(GTK_LAYOUT(layout),image,0,0);
gtk_layout_move(GTK_LAYOUT(layout),button_running,0,100);
gtk_layout_move(GTK_LAYOUT(layout),button_stop,0,130);
gtk_signal_connect (GTK_OBJECT(button_running), "clicked",GTK_SIGNAL_FUNC (on_running_clicked),image);
gtk_signal_connect (GTK_OBJECT(button_stop), "clicked",GTK_SIGNAL_FUNC (on_stop_clicked),image);
gtk_signal_connect (GTK_OBJECT(window),"delete-event",GTK_SIGNAL_FUNC (gtk_main_quit),NULL);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
废话不多说了,这就是你要的,running.gif对应你跑步的gif,stop对应你静止的gif,至于走路,我相信你自己一定会改啦
#include
void on_running_clicked(GtkButton *button,gpointer image)
{
gtk_image_set_from_file(GTK_IMAGE(image),"running.gif");
}
void on_stop_clicked(GtkButton *button,gpointer image)
{
gtk_image_set_from_file(GTK_IMAGE(image),"stop.gif");
}
int main(int argc,char *argv[])
{
gtk_init (&argc, &argv);
GtkWidget *window,*image,*layout,*button_running,*button_stop;
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(window,300,200);
layout=gtk_layout_new(NULL,NULL);
image=gtk_image_new();
button_running=gtk_button_new_with_label("running");
button_stop=gtk_button_new_with_label("stop");
gtk_container_add(GTK_CONTAINER(window),layout);
gtk_container_add(GTK_CONTAINER(layout),image);
gtk_container_add(GTK_CONTAINER(layout),button_running);
gtk_container_add(GTK_CONTAINER(layout),button_stop);
gtk_layout_move(GTK_LAYOUT(layout),image,0,0);
gtk_layout_move(GTK_LAYOUT(layout),button_running,0,100);
gtk_layout_move(GTK_LAYOUT(layout),button_stop,0,130);
gtk_signal_connect (GTK_OBJECT(button_running), "clicked",GTK_SIGNAL_FUNC (on_running_clicked),image);
gtk_signal_connect (GTK_OBJECT(button_stop), "clicked",GTK_SIGNAL_FUNC (on_stop_clicked),image);
gtk_signal_connect (GTK_OBJECT(window),"delete-event",GTK_SIGNAL_FUNC (gtk_main_quit),NULL);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
废话不多说了,这就是你要的,running.gif对应你跑步的gif,stop对应你静止的gif,至于走路,我相信你自己一定会改啦
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯