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 / Need Help With Point and Click

Author
Message
Newbie12321
8
Years of Service
User Offline
Joined: 2nd Jul 2011
Location:
Posted: 17th Jun 2012 15:42
Hello everyone, it has been awhile since I last used darkGDK and i have been trying to make a Point and click type thing, like i click in the screen and a shape moves there then stops when it is there, i am familiar with visual basic and got this working very easily but when i try to incorporate it in darkGDK it doesn't want to work

It complies fine and everything it Just doesn't do what I want it to do. Can Someone Please tell me what I have done wrong, I am a newbie so sorry if my code is bad.


#include "DarkGDK.h"
int playerimg = 1;
int playerspr = 2;
int PosX;
int PosY;
int playerX;
int playerY;
void movement() {
playerX = dbSpriteX(playerspr);
playerY = dbSpriteY(playerspr);
if (dbMouseClick() == 1)
{
PosX = dbMouseX();
PosY = dbMouseY();


}

if (playerX > PosX)
{
playerX = playerX + 10;

}

}


void player()
{
dbSetImageColorKey(255,0,255);
dbLoadImage("Images//player.bmp",playerimg);
dbSprite(playerspr,320,240,playerimg);
dbOffsetSprite(playerspr,dbSpriteWidth(playerspr) /2 ,dbSpriteHeight(playerspr) / 2);

}

void DarkGDK ( void )
{

player();

movement();


dbSyncOn ( );
dbSyncRate ( 60 );


while ( LoopGDK ( ) )
{

dbSync ( );
}


return;
}
Marsh0
10
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 18th Jun 2012 06:53 Edited at: 18th Jun 2012 10:15
You are setting a position variable but nothing is using it.

Try throwing in a dbSprite(playerimg,PosX,PosY,playerimg); Also move your movement function into the loop so it runs.

This works



Your signature has been erased by a mod - Please reduce it to 600x120 maximum size
Newbie12321
8
Years of Service
User Offline
Joined: 2nd Jul 2011
Location:
Posted: 18th Jun 2012 11:21
Firstly, thanks for the reply, I tried the code you gave me and it work but it make the image jump to the position, is there any way to make it so you can actually see it moving there. sorry for my noobyness
Newbie12321
8
Years of Service
User Offline
Joined: 2nd Jul 2011
Location:
Posted: 18th Jun 2012 13:00
OK I Got it working, Kinda, there is something that doesn't like something else, it works and moves but the sprite goes wired and moves back and forward (or left and right) very very fast so it looks like its vibrating. Here is my code (Someone may be able to work out the problem) =D.

#include "DarkGDK.h"

int backDropImg = 1;
int backDropSpr = 2;
int playerimg = 3;
int playerspr = 4;
int PosX;
int PosY;
int playerX;
int playerY;
bool move = false;

void movement() {


if (dbMouseClick() == 1)
{
move = true;
PosX = dbMouseX();
PosY = dbMouseY();
}

if (playerX > PosX && move == true)
{
dbRotateSprite(playerspr,270);
dbMoveSprite(playerspr,3);
}else if (playerX < PosX)
{
dbRotateSprite(playerspr,90);
dbMoveSprite(playerspr,3);
}

if (playerY > PosY && move == true) {
dbRotateSprite(playerspr, 360);
dbMoveSprite(playerspr,3);

}else if (playerY < PosY)
{
dbRotateSprite(playerspr,180);
dbMoveSprite(playerspr,3);
}

}



void loadImg()
{
dbSetImageColorKey(255,0,255);
dbLoadImage("Images//BackDrop.bmp",backDropImg);
dbSprite(backDropSpr,0,0,backDropImg);
dbLoadImage("Images//player.bmp",playerimg);
dbSprite(playerspr,320,240,playerimg);
dbOffsetSprite(playerspr,dbSpriteWidth(playerspr) /2 ,dbSpriteHeight(playerspr) / 2);

}

void DarkGDK ( void )
{

loadImg();




dbSyncOn ( );
dbSyncRate ( 60 );


while ( LoopGDK ( ) )
{
playerX = dbSpriteX(playerspr);
playerY = dbSpriteY(playerspr);
movement();
dbSync ( );
}


return;
}
Marsh0
10
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 18th Jun 2012 20:34 Edited at: 18th Jun 2012 20:38
Can you start putting your code in code tags? Its kind of hard to work with without the formatting.

Anyway, your problem is that you are increasing the move by 3. So most likely the image will never be at the location you want. It will always jump by 3 more to correct itself.

I added a check to see if it was close enough to the location and stop. This is a kind of roundabout way but works.



Your signature has been erased by a mod - Please reduce it to 600x120 maximum size

Login to post a reply

Server time is: 2019-08-25 00:01:46
Your offset time is: 2019-08-25 00:01:46