Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Moving Down PNG ALLEGRO 5

This thread is locked; no one can reply to it. rss feed Print
Moving Down PNG ALLEGRO 5
LegAlien
Member #16,674
May 2017

How can i move down png in allegro5??

Eric Johnson
Member #14,841
January 2013
avatar

What do you mean exactly? Are you asking how to set the order in which an image is drawn? If so, images are drawn from back to front in the order that you draw them. So if you draw bitmaps 1, 2, 3, and 4, the result will be that 1 is in the far "background" and 4 is in the "front". Is that what you meant?

--
EricII on #allegro.
My Games
Momo (my JS game-making library)

LegAlien
Member #16,674
May 2017

ı want to slide down coins upthere

Eric Johnson
Member #14,841
January 2013
avatar

You can move a bitmap by setting its X and Y coordinates during the render phase. Just move its Y axis up and down.

al_draw_bitmap(bitmap, x, y, flags);

--
EricII on #allegro.
My Games
Momo (my JS game-making library)

LegAlien
Member #16,674
May 2017

i could not:(

Eric Johnson
Member #14,841
January 2013
avatar

The attachment you provided is a Microsoft Visual Studio Solution file. It does not contain any source code, so it is not very helpful. Please take a look at the example file below:

#SelectExpand
1#include <iostream> 2 3#include <allegro5/allegro.h> 4#include <allegro5/allegro_image.h> 5#include <allegro5/allegro_primitives.h> 6 7using std::cout; 8 9int main() { 10 11 al_init(); 12 13 al_init_image_addon(); 14 15 al_init_primitives_addon(); 16 17 ALLEGRO_TIMER *timer = al_create_timer(1.0 / 60.0); 18 ALLEGRO_DISPLAY *display = al_create_display(768, 448); 19 ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue(); 20 21 al_register_event_source(event_queue, al_get_timer_event_source(timer)); 22 al_register_event_source(event_queue, al_get_display_event_source(display)); 23 24 int running = true; 25 int render = true; 26 27 // The coin will be drawn in the center of the display. 28 int coin_x = 768 / 2; 29 int coin_y = 448 / 2; 30 31 bool move_coin_down = true; 32 33 al_start_timer(timer); 34 35 while(running) { 36 37 ALLEGRO_EVENT event; 38 39 al_wait_for_event(event_queue, &event); 40 41 if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 42 43 // The window was closed. 44 running = false; 45 } 46 else if (event.type == ALLEGRO_EVENT_TIMER) { 47 48 render = true; 49 50 if (move_coin_down) { 51 52 if (coin_y > 224 + 128) { 53 54 move_coin_down = false; 55 } 56 57 // Move the coin down. 58 ++coin_y; 59 } 60 else { 61 62 if (coin_y < 224 - 128) { 63 64 move_coin_down = true; 65 } 66 67 // Move the coin up. 68 --coin_y; 69 } 70 } 71 72 if (render && al_is_event_queue_empty(event_queue)) { 73 74 render = false; 75 76 // Clear the display to black. 77 al_clear_to_color(al_map_rgb(0, 0, 0)); 78 79 // Draw a yellow coin. 80 al_draw_filled_circle(coin_x, coin_y, 32, al_map_rgb(255, 255, 0)); 81 82 al_flip_display(); 83 } 84 } 85}

The above draws a coin (represented by a yellow circle) and slowly moves it up and down. The vertical movement is dictated by the coin's Y value (coin_y), which is updated every frame in the update phase.

--
EricII on #allegro.
My Games
Momo (my JS game-making library)

LegAlien
Member #16,674
May 2017

What should ı change?

Eric Johnson
Member #14,841
January 2013
avatar

You should change the Y axis of your bitmaps, like in the example I posted.

--
EricII on #allegro.
My Games
Momo (my JS game-making library)

LegAlien
Member #16,674
May 2017

thanks but i tried its not working

jmasterx
Member #11,410
October 2009

LegAlien said:

thanks but i tried its not working

Do you really think that sort of response will help us help you? Try to think about how you can describe in detail what it is you did.

-Create a datastruct:

struct Coin
{
   int x;
   int y;
   ALLEGRO_BITMAP* image;
}

-Create a new Coin
-Initialize the starting point
-When the timer ticks:

coin.y += COIN_SPEED;

-Then on render you draw the coin.

-The png moves down.

Go to: