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.

Newcomers DBPro Corner / Little sprite test gone wrong

Author
Message
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 16th Mar 2011 00:37
So im on the chapter about sprites in my book, and im having a few difficulties. For one, paste sprite does not work without sync which this book pre-dates so i cant exactly trust its contents as i would not know what sync was from the book, i learned it from some other tutorial and while i dont understand it i was able to sufficiently fix the problem with it.

Now i have not only gone through the chapter but also decided to have a little play of my own. My idea was to use move and rotate sprite under user commands to move a crappy little ship (drawn in less than 6 seconds with 2 arrow tools ) across the screen using only 'w' for forwards, 's' for back and 'a' and 'd' for the angle change. It worked and all was well so i decided to implement a little speed increaser so make the ship not immediately zoom off. So i kind of slow start to full speed boost over a small amount of time. That too was a success as it does work (it looks crap but it does work) but it cant be the best way as i could not think how to do it in a for loop or any other way except sticking the 'w' and 's' in a while loop (see for yourself, its not right).

However it did work so i then decided to place a little starfield background to test it and does it work? No, no it does not. I have read all the stuf on sprites and the blue background but unfortunately it is no use here and no doubt because i am updating my velocity in a while loop. So check it out if you wish and tell me what a fool i am and how i could have done it differently.

Attachments

Login to view attachments
Admiral MH
13
Years of Service
User Offline
Joined: 10th Feb 2011
Location: TX, USA
Posted: 16th Mar 2011 19:23
Quote: "For one, paste sprite does not work without sync"


Interesting... It might be a bug, since you code does not have the command for "Sync On" so it should update without calling the sync command.

In the following code I changed a few things.

Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 16th Mar 2011 20:15
Thats brilliant Admiral, thanks very much for that. This is what i need right now because at the point im at, i can just about think of a solution for a few problems here and there but i always go the long way around doing it and need smoenoe to show me the more obvious or cleaner quicker example so i can 'get it'. Take that above problem, i couldnt think of a way to get it to accellerate before hitting top speed, every idea i came up with to do it failed until i came across the while loop, which was the only way i could think of. I knew this wasnt they best way or particulaly the right way as it takes control from the game while in the while loop so i needed something like this to point out to me the other way of doing it. One day ill be able to come up with better solutions without thinking but for now my limited knowledge needs a bit of a push sometimes and this has helped me tremendously.
Many thanks for your help.

While playing around with the code (which because of the way it is done is so simple to change vaules to produce the desired results) i started pondering another question. How would i get it to decellerate to a stop when the player stops moving the badly drawn arrows pasted together and coloured grey*. Would i go about this by adding another If statement perhaps - If Keystate(17) = 0 then copy part of the code from the backwards movement and vice versa for backwards. I cant think of a good way right now?

*read - ship
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 16th Mar 2011 20:31
I came up with a little solution but im not sure if its the best way. It seems to work but if i could do it differently/better i would love to know.

Admiral MH
13
Years of Service
User Offline
Joined: 10th Feb 2011
Location: TX, USA
Posted: 17th Mar 2011 19:21
Quote: "Thats brilliant Admiral, thanks very much for that. This is what i need right now because at the point im at, i can just about think of a solution for a few problems here and there but i always go the long way around doing it and need smoenoe to show me the more obvious or cleaner quicker example so i can 'get it'. Take that above problem, i couldnt think of a way to get it to accellerate before hitting top speed, every idea i came up with to do it failed until i came across the while loop, which was the only way i could think of. I knew this wasnt they best way or particulaly the right way as it takes control from the game while in the while loop so i needed something like this to point out to me the other way of doing it. One day ill be able to come up with better solutions without thinking but for now my limited knowledge needs a bit of a push sometimes and this has helped me tremendously.
Many thanks for your help."


No problem. I started out like that too, having very inefficient code for things that are so simple.

Quote: "While playing around with the code (which because of the way it is done is so simple to change vaules to produce the desired results) i started pondering another question. How would i get it to decellerate to a stop when the player stops moving the badly drawn arrows pasted together and coloured grey*. Would i go about this by adding another If statement perhaps - If Keystate(17) = 0 then copy part of the code from the backwards movement and vice versa for backwards. I cant think of a good way right now?"


Your code posted below works good. I don't see anything wrong with it. Good job!
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 18th Mar 2011 01:34
Im glad to hear others may have suffered the same plight as me when first starting out It is a bit daunting and i get very pleased with myself when i do actually crack a problem, but then only to realise i could have done it a hundred times easier doesnt dampen the spirits it sort of gets your brain working in a kind of 'oh yeah i get it' manner. Its all good.

Login to post a reply

Server time is: 2024-11-22 22:58:49
Your offset time is: 2024-11-22 22:58:49