标签: allegro5

allegro 5以一定的间隔执行事件

我正在使用快艇5进行我的第一场比赛,这是一场蛇比赛.为了移动蛇游戏,我想使用我制作的方格,所以蛇会定期移动.

如何使用计时器在一定时间内发生事件?

例如,我希望我的蛇在方向设置中每秒移动一次,我知道如何控制他,但我不知道如何创建一个以某个间隔发生的事件.我在Windows XP SP3上使用Codeblocks IDE

c++ allegro allegro5

4
推荐指数
1
解决办法
1193
查看次数

C中架构x86_64的未定义符号

今天我为C安装了Allegro游戏编程库,我试图包含其中一个头文件但是当我尝试gcc -I./include example.c -o a.exe在终端中执行时,我不断收到此错误:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
     (maybe you meant: __al_mangled_main)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我使用以下说明安装了Allegro 5:https://wiki.allegro.cc/index.php?title = Install_Allegro5_From_GIT/OSX

example.c代码:

#include <stdio.h>
#include <allegro5/allegro.h>

int main(int argc, const char *argv[]){
    puts(“Hello, world!”);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c allegro5

4
推荐指数
1
解决办法
1290
查看次数

使用allegro 5和g ++编译C++代码

为了使用allegro 5编译代码,我需要添加到g ++中的标志是什么?我试过了

g++ allegro5test.cpp -o allegro5test `allegro-config --libs`
Run Code Online (Sandbox Code Playgroud)

但那不起作用.我正在使用ubuntu 11.04.我使用http://wiki.allegro.cc/index.php?title=Install_Allegro5_From_SVN/Linux/Debian上的说明安装了allegro 5

我试过了:

g++ allegro5test.cpp -o allegro5test `allegro-config --cflags --libs`
Run Code Online (Sandbox Code Playgroud)

它还提供了一堆未定义的错误,例如:对"al_install_system"的未定义引用

allegro-config --cflags --libs 输出:

-I/usr/local/include
-L/usr/local/lib -lalleg
Run Code Online (Sandbox Code Playgroud)

c++ g++ allegro allegro5

3
推荐指数
1
解决办法
9253
查看次数

你怎么能有效地创建一个allegro 5标题菜单?

我正在使用Allegro 5中的第一个游戏,我已经有了标题菜单渲染,但是我想在菜单中添加可点击的文本.如何将其设置为当您将鼠标悬停在文本上时可以单击它?我正在考虑使用for语句检查像素对性能非常不利,这是我到目前为止所做的:

#include <allegro5\allegro.h>
#include <allegro5\allegro_image.h>
#include <allegro5\allegro_primitives.h>

const int width = 1280;
const int height = 720;

int main(void)
{
    al_init();

    al_init_primitives_addon();
    al_init_image_addon();

    ALLEGRO_DISPLAY *display = al_create_display(width, height);
    ALLEGRO_BITMAP *title = al_load_bitmap("titlemenu.bmp");

    al_clear_to_color(al_map_rgb(0, 0, 0));
    al_draw_bitmap(title, 0, 0, 0);
    al_flip_display();
    al_rest(3.0);
    al_destroy_display(display);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Windows XP SP3上的代码块

c++ allegro codeblocks allegro5

3
推荐指数
1
解决办法
4976
查看次数

在 Mac 上通过命令行编译 Allegro 5 程序

我按照步骤从他们的 wiki(在这里找到:https : //wiki.allegro.cc/index.php?title=Main_Page)构建和安装 Allegro 5,并且似乎没有问题地成功了。

allegro 已安装到以下(如 wiki 所建议的)/usr/local/include 和 usr/local/lib 中,我已确认 allegro 在那里。

然后我在vim中编写了以下代码:

#include <stdio.h>
#include <allegro5/allegro.h>

int main(int argc, char **argv)
{
   ALLEGRO_DISPLAY *display = NULL;

   if(!al_init())
   {
      fprintf(stderr, "failed to initialize allegro!\n");
      return -1;
   }

   display = al_create_display(640, 480);

   if(!display)
   {
      fprintf(stderr, "failed to create display!\n");
      return -1;
   }

   al_clear_to_color(al_map_rgb(0,0,0));
   al_flip_display();
   al_rest(10.0);
   al_destroy_display(display);

   return 0;
}
Run Code Online (Sandbox Code Playgroud)

我是使用 Unix 的新手,并且只用 g++ 编译过 C++ 程序,这些程序是简单的 hello world 文件,不需要库。

因此,在互联网上搜索后,我尝试了以下命令:

g++ hello.cpp -o hello `pkg-config --libs …
Run Code Online (Sandbox Code Playgroud)

c++ macos command-line g++ allegro5

3
推荐指数
1
解决办法
1339
查看次数

使用 CMake 和 Visual Studio 出现“无法解析的外部符号”错误

我正在尝试使用 CMake 在 Windows 上使用 Allegro5。我的“CMakeLists.txt”文件是

cmake_minimum_required (VERSION 3.8)

project("My Project")

set(SOURCE_FILES "main.cpp")
add_executable(core ${SOURCE_FILES})

set(ALLEGRO_INCLUDE ".\\dependencies\\allegro\\include")
set(ALLEGRO_LIB ".\\dependencies\\allegro\\lib")
set(ALLEGRO_DYLIB ".\\dependencies\\allegro\\bin\\*.dll")

include_directories(${ALLEGRO_INCLUDE})
link_directories(${ALLEGRO_LIB})
file(GLOB LIBRARIES ${ALLEGRO_DYLIB})

target_link_libraries(core ${LIBRARIES} ${ALLEGRO_DYLIB})
Run Code Online (Sandbox Code Playgroud)

我的目录结构是:

root
|--CMakeLists.txt
|--main.cpp
|--build # this is where VS project files are generated.
|--dependencies
      |--allegro
           |--include
           |--lib
           |--bin
Run Code Online (Sandbox Code Playgroud)

我的main.cpp

#include <iostream>
#include <allegro5/allegro.h>

int main(int argc, char *args[])
{
    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 480;

    ALLEGRO_DISPLAY *window = al_create_display(SCREEN_WIDTH, SCREEN_HEIGHT);
    std::system("pause");
    return 0;
} …
Run Code Online (Sandbox Code Playgroud)

c++ windows cmake allegro5 visual-studio-2017

3
推荐指数
1
解决办法
2万
查看次数

Ubuntu中的Allegro:对"al_install_system"的未定义引用

我今天尝试安装Allegro库.我在C++方面有相同的经验,但似乎我没有做过这样的事情.我从源代码编译了Allegro 5.0并将其放在/usr/lib/gcc/i486-linux-gnu/4.4/include/allegro5中.但是当我尝试编译我的代码时,会出现这种情况:

    > g++ test2.cc -o test2
/home/chris/Desktop/c++/test2/.objs/main.o||In function `main':|
main.cpp:(.text+0x22)||undefined reference to `al_install_system'|
main.cpp:(.text+0x3e)||undefined reference to `al_create_display'|
main.cpp:(.text+0x6b)||undefined reference to `al_map_rgb'|
main.cpp:(.text+0x8e)||undefined reference to `al_clear_to_color'|
main.cpp:(.text+0x93)||undefined reference to `al_flip_display'|
main.cpp:(.text+0xa1)||undefined reference to `al_rest'|
main.cpp:(.text+0xa9)||undefined reference to `al_destroy_display'|
||=== Build finished: 7 errors, 0 warnings ===|
Run Code Online (Sandbox Code Playgroud)

我正在使用的代码:

#include <stdio.h>
#include <allegro5/allegro.h>

int main(int argc, char **argv)
{
   ALLEGRO_DISPLAY *display = NULL;

   if(!al_init()) {
      fprintf(stderr, "failed to initialize allegro!\n");
      return -1;
   }

   display = al_create_display(640, 480);
   if(!display) {
      fprintf(stderr, "failed to …
Run Code Online (Sandbox Code Playgroud)

c++ g++ allegro5 ubuntu-10.04

2
推荐指数
1
解决办法
8399
查看次数

为什么allegro会自动处理最小化按钮,但不能关闭按钮?

以下是来自Allegro5教程的示例:(要查看原始示例,请点击链接,我已将其简化为插图目的.

#include <allegro5/allegro.h>

int main(int argc, char **argv)
{
   ALLEGRO_DISPLAY *display = NULL;
   ALLEGRO_EVENT_QUEUE *event_queue = NULL;
   al_init()
   display = al_create_display(640, 480);
   event_queue = al_create_event_queue();
   al_register_event_source(event_queue, al_get_display_event_source(display));
   al_clear_to_color(al_map_rgb(0,0,0));
   al_flip_display();
   while(1)
   {
      ALLEGRO_EVENT ev;
      ALLEGRO_TIMEOUT timeout;
      al_init_timeout(&timeout, 0.06);
      bool get_event = al_wait_for_event_until(event_queue, &ev, &timeout);
      //-->// if(get_event && ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
      //-->//   break;
      //-->// }

      al_clear_to_color(al_map_rgb(0,0,0));
      al_flip_display();
   }

   al_destroy_display(display);
   al_destroy_event_queue(event_queue);

   return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果我不手动检查ALLEGRO_EVENT_DISPLAY_CLOSE,那么我无法关闭窗口或终止程序(不通过任务管理器终止进程).我理解这一点.但在这种情况下,我不明白最小化按钮如何工作,没有我手动处理它.有人可以解释一下吗?

c c++ windows allegro allegro5

2
推荐指数
1
解决办法
1174
查看次数

Allegro 5 中的抗锯齿

绘图时如何让 allegro 5 使用抗锯齿?我需要对角线显得平滑。目前,它们只是阴影像素线,边缘看起来很硬。

c++ allegro antialiasing allegro5

1
推荐指数
1
解决办法
2617
查看次数

运行时检查失败#3 - 正在使用变量'direct'而不进行初始化

在这部分代码中是一个错误.它说

"运行时检查失败#3 - 正在使用变量'direct'而未进行初始化."

我该如何解决这个错误?

bool loop=true;
int direct;

al_install_keyboard();

ALLEGRO_TIMER *timer = al_create_timer (0.4);
ALLEGRO_EVENT_QUEUE *keystroke = al_create_event_queue();
al_register_event_source(keystroke ,al_get_keyboard_event_source() );
al_register_event_source (keystroke , al_get_timer_event_source(timer));
al_start_timer(timer);

do{
    ALLEGRO_EVENT input;
    al_wait_for_event(keystroke , &input );
    if (input.type == ALLEGRO_EVENT_KEY_DOWN){
        switch(input.keyboard.keycode){
        case ALLEGRO_KEY_DOWN: direct=DOWN; break;
        case ALLEGRO_KEY_UP : direct=UP;break;
        case ALLEGRO_KEY_LEFT: direct=LEFT;break;
        case ALLEGRO_KEY_RIGHT: direct=RIGHT;break;
        case ALLEGRO_KEY_ESCAPE: loop= false;
        }
    }

    if(input.type==ALLEGRO_EVENT_TIMER){
        switch(direct){
        case DOWN: moove_snake(DOWN) ; break;
        case UP: moove_snake(UP) ; break;
        case LEFT: moove_snake(LEFT) ; break;
        case RIGHT: moove_snake(RIGHT) ; …
Run Code Online (Sandbox Code Playgroud)

c++ allegro5

1
推荐指数
1
解决办法
2万
查看次数

如何使用Allegro Bitmaps使用智能指针?

我已经决定我已经厌倦了决定哪些类负责删除哪些位图.我试图重写我的代码以使用自定义删除器的智能指针al_destroy_bitmap

我的代码非常简单.

shared_ptr<ALLEGRO_BITMAP> test = make_shared<ALLEGRO_BITMAP>(al_load_bitmap("hello.png"), al_destroy_bitmap);
Run Code Online (Sandbox Code Playgroud)

我遇到了一些我似乎无法解决的错误.

error C2079: 'std::_Get_align<ALLEGRO_BITMAP>::Elt2' uses undefined struct 'ALLEGRO_BITMAP'
error C2079: 'std::_Get_align<ALLEGRO_BITMAP>::Elt0' uses undefined struct 'ALLEGRO_BITMAP'
error C2027: use of undefined type 'ALLEGRO_BITMAP'
error C2027: use of undefined type 'ALLEGRO_BITMAP'
Run Code Online (Sandbox Code Playgroud)

解决我的问题的其他解决方案是创建一个Bitmap类来包装所有Allegro的东西,但这看起来很难看,我认为我不应该这样做.另外,我已经到处使用其他的allegro函数,然后我想为ALLEGRO_SAMPLE和编写相同类型的类ALLEGRO_FONT.我真的不喜欢这样做.

如何在Allegro位图中使用智能指针?

编辑:也许为非Allegro编码员提供ALLEGRO_BITMAP如何工作的感觉,我将在下面发布一些代码

ALLEGRO_BITMAP *test = al_load_bitmap("hello.png") // This works
ALLEGRO_BITMAP test1; // This fails with error C2079 undefined struct ALLEGRO_BITMAP. I expect this here.
Run Code Online (Sandbox Code Playgroud)

c++ smart-pointers allegro allegro5

1
推荐指数
1
解决办法
260
查看次数

C++ Allegro 5错误

我试图用youtube教程学习一些allegro 5原则,这是我的第一个问题.

#include<allegro5/allegro.h> 
#include<allegro5/allegro_native_dialog.h> 
#include<allegro5/allegro_primitives.h>
#include<Windows.h>

#define ScreenWidth 800 
#define ScreenHeight 600

int main()
{
    ALLEGRO_DISPLAY *display; 

    if(!al_init())
    {
        al_show_native_message_box(NULL, NULL,  "Error" ,  "Could not initialize Allegro 5" , NULL, ALLEGRO_MESSAGEBOX_ERROR); 
        return -1;
    }
    display = al_create_display(ScreenWidth, ScreenHeight); 

    if(!display)
    {
        al_show_native_message_box(NULL, NULL,  "Error" ,  "Could not create Allegro 5 display" , NULL, ALLEGRO_MESSAGEBOX_ERROR);
        return -1;
    }

    al_set_new_display_flags(ALLEGRO_NOFRAME);
    al_set_window_position(display, 200, 100);
    al_set_window_title(display,  "CodingMadeEasy" );


    system("pause");
    al_draw_triangle(10, 10, 20, 10, 25, 50, al_map_rgb(255, 0, 0), 1.0);
    system("pause");


    al_flip_display();
    al_rest(5.0);
    al_destroy_display(display);

    return 0; …
Run Code Online (Sandbox Code Playgroud)

c++ allegro allegro5

0
推荐指数
1
解决办法
509
查看次数