|
Yet another problem with animations.... |
miguel meza
Member #5,447
January 2005
|
well, in my 2D fighting game (DBZ hyper dimension clon), i have some problems with the logic when animating a character: I do something like this when animating a fighter, for example when he jumps (this is onlye a test code, i am going to do a fine method to save code): stretch_sprite(buffer, background, 0, screenY1, SCREEN_WIDTH ,screenY2); masked_blit(gokuss1, buffer, 96*2, 96*2, 100,150, 96,96); // jumps blit(buffer, screen, 0,0,0,0,SCREEN_WIDTH,SCREEN_HEIGHT); rest(50); clear_bitmap(buffer); // Clear the contents of the buffer bitmap stretch_sprite(buffer, background, 0, screenY1, SCREEN_WIDTH ,screenY2); masked_blit(gokuss1, buffer, 96*2, 96*2, 100,200, 96,96); // goes down blit(buffer, screen, 0,0,0,0,SCREEN_WIDTH,SCREEN_HEIGHT); rest(50); clear_bitmap(buffer); // Clear the contents of the buffer bitmap
the problem is: And if i put that code, the game CANT do any other thing. For example,that the enemy attacks me when i jump. What should i do? thanks... |
Elverion
Member #6,239
September 2005
|
Look into allegro timers. Using rest to adjust the speed of your game is a no-no. Second of all, make the character an object or struct. When they are jumping, you want to do something like y = y - 2; (this is a very poor jump...search the forum for more in-depth jump stuff). Once you're into your draw section, you masked_blit the sprite onto the characters x and y coordinates (give or take some offset values). -- |
Archon
Member #4,195
January 2004
|
If your 'rest(50)' actually worked like you'd like, it'd actually just have 50 millisecond gaps between the animations, but it would differ depending on the number of sprites to draw. What you really want is to prioritise the processing and only then, the drawing. Use a timer to increment about 30 times per second. When the ticks are above 0, decrement it by one and then do your processing. When the processing ticks remaining is 0, then do the drawing. |
miguel meza
Member #5,447
January 2005
|
i dont understand very good... i have this bitmap: i already created my class for sprites, and for drawing i use this: sprGoku.drawSprite( sprGoku.m_partX, sprGoku.m_partY, sprGoku.m_posX , sprGoku.m_posY ); that mainly does this: masked_blit( m_bitmap, g_buffer, partX, partY, posX, posY, m_sizeX, m_sizeY );
i subdivided my bitmap in parts of 96*96 i already use timers:
in my "Do GameLogic" i do this: void DoGameLogic() { CheckCollision(); // does nothing in this moment if( keypressed() ) CheckMovement(); } this the "short" version of CheckMovement() void CheckMovement() { if ( key[KEY_UP] ) { // only set the partX1,X2...partY1,Y2....etc of the bitmaps CalculateJumpPos(); }
and in my "renderScene" i call the method to do the JumpAnim() (if needed)
so now that you know what am i doing........ |
miran
Member #2,407
June 2002
|
Get rid of rest(). Use timers instead. What you're doing now is you draw your sprites and in between wait more than a quarter of a second. This will give you roughly 3 FPS at best. EDIT: Actually I misunderstood. Do this: while (not done) { if (timer ticked) { // get input, update player position, etc. do_game_logic() } if (need to redraw) { // here you don't update player position or animation sequence or anything like // that. you just draw the current frame at the current position. redraw_entire_scene() } }
-- |
miguel meza
Member #5,447
January 2005
|
ok, i got it. there will be a time when i need to flip the sprite. but there isnt a method to do that with blit or masked blit (which i need to draw only a part of the image). Allegro only has the draw_sprite_h_flip(bmp, sprite, posX, posY); but that doesnt works for me, because it will draw ALL the image. what can i do? 1.- Create a sub_bitmap that will be the part of the image i want to draw, and then i can use the draw_sprite_h_flip. BUT i will have to create the sub_bitmap every time the character move, which i think it could cause a BIG slowdown... or no? 2.- Have another image with the "parts" flipped horizontally. Isnt there any other solution? |
Archon
Member #4,195
January 2004
|
Quote: 2.- Have another image with the "parts" flipped horizontally.
From your two choices, this would be the better one. |
miguel meza
Member #5,447
January 2005
|
thanks. |
|