Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK .NET / [LOCKED] 2d Sprite game, the animation wont stop fast enough.

Author
Message
Netjack
14
Years of Service
User Offline
Joined: 18th May 2009
Location:
Posted: 27th May 2009 08:03
This would be my second post about the same project, my experience so far has been rather nice.

So anyway, I ran into the issue with the command dbPlaySprite () as playing the sprite would cause problems since the command will not stop playing the sprite until its gone through its rotation. For example dbPlaySprite ( 1, 1, 6, 60 ); if I bind the left arrow key, so that it will move left while playing those frames, and have
dbPlaySprite ( 1, 7, 12, 60 ); for the right key, so that the sprite will move right while playing those frames.

The issue is, if you where to switch the keys during the middle of playing the sprite, it will not switch to the other until it is finished with the first. Meaning that while moving to the left and quickly to the right, the dbPlaySprite () intended for the left button press would finish first before starting the other for te right.

So I decided to use something different, based off the tutorial, i set in int value for the current sprite dbSetSpriteFrame ( 1 , iPlayerFrame ); I ended up doing a series of if statments, but ran into a similar problem. The cycle for the sprite will not end until it gets to the a certain point. However, I do not know how to fix it so that it while the button is not being press, it will for to a default sprite for that direction, as well as make it quickly switch when I press another button.

The code should make is clearer. This is based off the dark Invaders code. As I'm trying to learn this before trying anything on my own.

Player.cpp

#include "DarkSDK.h"
#include "Player.h"
#include "Input.h"
//#include "Enemies.h"
//#include "Invader Text.h"


// player variables
// Player X position
int iPlayerX = 448;
// player Y position
int iPlayerY = 400;
// speed the player should move
int iPlayerSpeed = 2;
// current frame the player is on
int iPlayerFrame = 13;
// we increment this to form a delay for out animation
int iFrameAnimateDelay = 0;


void playerSetup ( void )
{
// the player animated sprite
dbCreateAnimatedSprite ( 1 , "Cronoo.bmp", 6, 3, 1 );
dbSprite ( 1 , iPlayerX , iPlayerY , 1 );
dbSetSpriteFrame ( 1 , iPlayerFrame );
dbSetSpritePriority ( 1 , 2 );
}

void playerUpdate ( void )
{

// see if the player ship needs to try and go left
if ( checkLeft() )
{
iPlayerX -= iPlayerSpeed;
if ( iPlayerX < 0 )
iPlayerX = 0;
iPlayerDirection = LEFT;
}
// see if the player ship needs to try and go right
else if ( checkRight() )
{
iPlayerX += iPlayerSpeed ;
if ( iPlayerX > 1024 - 128 )
iPlayerX = 1024 - 128;
iPlayerDirection = RIGHT;
}
// not left or right, so lets face straight
else
iPlayerDirection = STRAIGHT;

// animate the player
playerAnimate();
// check for player firing and update firing if a bullet is already in action

player.h #pragma once

void playerSetup ( void );
void playerUpdate ( void );
void playerAnimate ( void );



extern int iPlayerX;
extern int iPlayerY;
extern int iPlayerSpeed;
extern int iPlayerFrame;
extern int iFrameAnimateDelay;

Input.cpp#include "DarkSDK.h"
#include "Input.h"

// check the keys we have assigned to be the fire key
// check the keys we have assigned to be the left key
bool checkLeft ( void )
{

if ( dbKeyState ( 203 ) || dbKeyState ( 30 ) )
return true;

return false;
}

// check the keys we have assigned to be the right key
bool checkRight ( void )
{

if ( dbKeyState ( 205 ) || dbKeyState ( 32 ) )
return true;

return false;
}

Input.h
#pragma once

bool checkFire ( void );
bool checkLeft ( void );
bool checkRight ( void );

Main.cpp
#include "DarkGDK.h"
#include "Input.h"
#include "Player.h"
#include "windows.h"


void DarkGDK ( void )
dbSyncOn ( );
dbSyncRate ( 60 );
dbDisableEscapeKey ( );
dbRandomize ( dbTimer ( ) );

while ( LoopGDK ( ) )
{

backdropUpdate();

playerUpdate ();
playerAnimate ();
playerUpdateFire ();
if ( dbEscapeKey ( ) )
break;

dbSync ( );
}
return;
}
AlexI
19
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Posted: 27th May 2009 22:21
This is the DarkGDK.NET forum, the .NET version is for C#,VB and managed C++. You are using DarkGDK which is unmanaged C++. The languages are very different, please post the topic in the DarkGDK forum.

Login to post a reply

Server time is: 2024-03-29 01:48:13
Your offset time is: 2024-03-29 01:48:13