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 / move sprite in DGDK

Author
Message
ketchup mustard
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 26th Nov 2008 18:57
i cant get my sprite to move with this code : (
Do i need the dbOffsetSprite function?
it seems like this should work, what do u think im doing wrong?



Don't Clap, Just Throw Money!
ketchup mustard
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 26th Nov 2008 19:15
SCRATCH THAT ><

i can get him to move with my update code:


EXCEPT, he (the sprite) only moves ten pixels left or right once. How do I keep him moving as long as I hold the button? I'm thinking of a sidescroll game where the character moves left or right.

Don't Clap, Just Throw Money!
iceloop
15
Years of Service
User Offline
Joined: 11th Oct 2008
Location:
Posted: 26th Nov 2008 19:29
Try this:
ketchup mustard
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 26th Nov 2008 19:59
Yo icy, its still doin the same crap. I cant make my sprite move any more than 10 px left or right. Do u reckon i need another instance or some function?

Don't Clap, Just Throw Money!
iceloop
15
Years of Service
User Offline
Joined: 11th Oct 2008
Location:
Posted: 27th Nov 2008 01:52
well, i have my code split up into two functions, one to setup the sprite and another to update the movements, but i'm not sure why your code isn't working because that is pretty much how i have it in my code to move my sprite left & right.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 27th Nov 2008 05:54
Question on original code, is this in a loop? If so, is the

int mX = 10;
int mY = 200;

inside the loop?

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
ketchup mustard
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 6th Dec 2008 02:28
its only in the main GDK Loop... I created a GameStart Function, and then I used the declaration in the main loop, where what little character programming i have is used in the GameStart Function. Including my variables mX and mY. thx^^

Don't Clap, Just Throw Money!
ketchup mustard
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 7th Dec 2008 19:56
i still have the same problem, i know its an age-old problem but i searched and searched again for help. Someone plz brighten the path; my sprite wont move more than 10 pixels left or right. Lilith, u reckon its a loop problem? i used a for loop once, but it froze the program :/ plz help THX YALL

Don't Clap, Just Throw Money!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Dec 2008 21:16
Post the code. Don't keep everyone guessing.

What Lilith was asking was if you reset the variables inside the loop:


If you have code like that, then of course the numbers are going to be reset each time the loop runs.

ketchup mustard
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 10th Dec 2008 01:24
yo Ian ^^ my code is so close to working. only problem is, when i press the left/right arrow key, it freezes my character in that position until i let go of said key. So it looks like its trying to do the right thing; plz check my code:


its so close, it just probably needs one fix up. Thx Lilith and Ian and Icy!

Don't Clap, Just Throw Money!
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 10th Dec 2008 01:34
Assuming that mX and mY don't get reset in a surrounding loop the one thing I see wrong with the above code is that if you hold a key down it will reposition the sprite but it never updates the position visually. You'd need a dbSync() to make that happen.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
ketchup mustard
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 10th Dec 2008 03:57
say Lil, i tried the dbSync(); command, and im assuming its doing the right thing? It takes away my background and goes to the original blue color background, while my sprite does move left and right, it will stay in one frame from when i clicked the arrow key to move it. Also, when I let go of the arrow key, it resets to its previous position. Maybe i just need to update/advance my code accordingly? and gyaawww, i preciate ur patience ^^

Don't Clap, Just Throw Money!
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 10th Dec 2008 04:27
You've got to be resetting your mX amd mY values inside a loop. I'd really have to see the entire code or at least the code that encloses this other loop.

If your code segment that we've been discussing is inside another loop I'd change the while statement to an if statement and update background and do the sync in the outside loop.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
ketchup mustard
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 10th Dec 2008 04:39


MY GameStart function declaration was placed directly in the while loop main loop.



Don't Clap, Just Throw Money!
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 10th Dec 2008 05:39
I had to change some of the code simply because I don't have your graphics and I don't have time to put one together. The code below works, without background since I commented it out. I'm seeing what seem to me to be some inconsistencies that I'll point out and let you determine if they're so.

You're doing a dbCreateAnimatedSprite and assigning the image number 2. Yet when you dbPlaySprite and dbSprite you reference image 1. Maybe I'm overlooking something.




I changed the mX++ and mX-- to ++mX and --mX respectively. C/C++ has prefix and postfix incrementation/decrement. When you say mX++ the program will use the current value of mX and at some point before the statement is completed will increment mX. If you say ++mX the value of mX is incremented and then the value is used in the expression.

Now, as shown above, substituting my own graphic, the sprite will move right as long as I hold the right arrow key down. Ditto for the left arrow key. If I hold one down while switching to the other I can move back and forth, though the left arrow key takes precedence.

As soon as I release the keys the sprite snaps back to its default position. Here's what's happening. GameStart() is called over and over again. It's inside the

while (LoopGDK())

loop. So when you release the key GameStart () exits but the outside loop calls it back up again and the first thing that it does is reset mX and mY back to their starting positions.

I've moved the dbSync to the end of the function since you want to sync after you've changed the position. Visually it doesn't make much difference but it might cause a problem later that requires debugging.

Although I haven't done it in the code above, I'd take the dbLoadBitmap calls out of the if statements and make only one call to it at the beginning of the loop.

You probably want to also do some tests to make sure that mX never goes below 0 or above the width of the screen less the width of the sprite.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
ketchup mustard
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 10th Dec 2008 22:58
alright, i redid everything u told me to. It's looking pretty good.

it still resets position, but i think i can figure that out: i should just find the position of the sprite at the new location when arrow key is left unpressed, and have the program code the new location as the x and, later, y coordinates.

When the bitmap background is coded inside the while loop, it slows the sprite movement. I think its because i have 192 mb RAM for my laptop. this is definately not a gaming laptop :/

Don't Clap, Just Throw Money!
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 10th Dec 2008 23:13
Assuming that StartGame() doesn't exit until the game is over the reset is moot unless you come back into StartGame().

I'm not sure that dbLoadBitmap needs to be called inside the while loop. The implication is that it loads the image from file every time. Ostensibly if you load it once it automatically becomes the background. However I've seen instances where it didn't behave that way for me. I'd try loading it as an image and assigning it to a sprite positioned at (0, 0). Just give it a lower priority than any other sprites.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
ketchup mustard
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 11th Dec 2008 22:18
righteous, thk yall so much. i think our examples prove to be good help for anyone else looking to budge a sprite. later ^___^

Don't Clap, Just Throw Money!
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 12th Dec 2008 03:53
Still helping people I see Lilith... Cool
--Jason

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 12th Dec 2008 04:21
Yeah, but I did have a slow down in there and will only have time to help sporatically. My projects have taken a backseat because my home and work lives have gotten crowded.

How 'bout you? If I remember you were off studying DirectX and writing your own engine.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 12th Dec 2008 04:24
Yuppers - made a neat dx renderer for a company I'm working with... and now will be doing a matlab + dx9 hybrid for work related etc.

dx9 is fast... but it's a lot of work for an entire physics enabled, oop game engine... dunno - don't want to over-hijack this thread.. but I'm still around

--Jason

Login to post a reply

Server time is: 2024-09-30 13:24:19
Your offset time is: 2024-09-30 13:24:19