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.

2D All the way! / Random blue screen when I press spacebar?

Author
Message
Neon Knight
18
Years of Service
User Offline
Joined: 28th Oct 2006
Location:
Posted: 27th Apr 2007 23:41
Right, I've posted this in the dbpro forum, but my problem has not as of yet been solved, so I thought I'd see what the people in the 2D forum make of it.

Right, I've currently been working on a top-down-tank shooter in DB pro.

I have the tank driving and turning with the arrow keys, and space bar to shoot. The problem I have, is that whenever I press the spacebar, the tank shoots alright, but instead of the black background I had before, I get a blue one. When I let go of spacebar, it returns to a black background.

Does anybody know how to solve this? thanks.

Here's my code:
(it's kinda spaghetti-coded, and not commented, Sorry...)


Thanks for any help you can give.

Also, another issue I've been having, is with the "rotate sprite" command. The problem is, the axle of rotation is in the top left hand corner, which is really annoying when driving my tank around because it kinda slides around. Is there any chance of setting the axle of rotation to the centre of the image?


Thank you very much for any help you can give in this matter.
zenassem
22
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 28th Apr 2007 01:24 Edited at: 28th Apr 2007 01:32
The second question is easier to answer:
Look at the Offset sprite command. you should be able to match the center with the anchor point with some trial and error.

=====

The first question is a little tougher, perhaps:
Your code is a little speghetti-ish, with Gosubs that don't really have a return. Like the Gosub to begingame:

Another problem is... when you hit the spacekey if the tank isn't outside the screen boarder you get stuck in an almost infinite loop becasue of "goto thing:". That logic might be off. This would cause you to get stuck with the tank moving but outside of any sync. You basically stalled the game loop.

More than likely what's happening is your code is getting stuck without a sync, and the 3d backdrop is rearing it's head (yes sprites in DBpro invoke 3d). So the backdrop is what you are seeing.

To fix it:
You can either use a method I learned from Indi in the newcomers board to color the backdrop black, or you can use a method of turning off the backdrop with the command backdrop off. and on certain situations cls* command at the beginning of your game loop (*this will require redrawing the screen every frame). If you are redrawing the screen you then should use set sprite command to turn off restore background. For these reasons and possibly speed dependent on what you are doing, indi's method might be easier for you to implement.


I'll post a link to that discussion (Just disregard the squabling between indi & I.)

You really need to look at how you can organize your code and get rid of most of those goto's and gosubs. You also need to make sure that whatever you do inside the gameloop, that you don't prevent the code from reaching the sync and restarting the loop.

Neon Knight
18
Years of Service
User Offline
Joined: 28th Oct 2006
Location:
Posted: 28th Apr 2007 12:33
Wow, thanks for the help in explaining that, it seems to make sense now.

And yeah, considering I've been programming now over 10 years, my organisation in my code is apalling and woeful.

The thing is, my dad (experienced programmer) told me when I was learning Qbasic (I was around 6 at the time) that I should always use gosubs whenever I can, because you never know when you need to use it again, and it saves time, is easier to edit and makes the program faster.
But yeah, that's quite bad. The thing is, "Loop Until X = y" doesn't seem to work for me, "while" doesn't seem to work, so I'm stuck having to physically break each loop with a goto/gosub.


Oh, and as for changing the background colour, turning it off, or using cls at the start of each game loop..

neither worked. I still get a blue screen.

It goes blue when I press space, and stays blue until the bullet leaves the screen.

Woe is me!
Neon Knight
18
Years of Service
User Offline
Joined: 28th Oct 2006
Location:
Posted: 28th Apr 2007 21:38
Sorry to bump, but I really want to get this sorted...
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 29th Apr 2007 02:28 Edited at: 29th Apr 2007 02:32
In order to prevent your project becoming too hard to handle, lay it out neatly. Think about using REMARK statements and FUNCTIONS in order to make this much easier to handle.

You can still deploy gosubs if you want but lay it out neatly and it will be easier to read.

This example is based from your code, but Ive drastically changed the commands layout as well as remark everything.




you forgot to setup the background colours etc.
On this line at the very top is this.


Neon Knight
18
Years of Service
User Offline
Joined: 28th Oct 2006
Location:
Posted: 29th Apr 2007 14:00 Edited at: 29th Apr 2007 14:30
Okay, I've commented my whole code through and rearranged some bits of it..

I've tried to get it as well laid out as possible.



And I still have a blue screen when the bullet is on the screen.

What can I do about this?
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 29th Apr 2007 14:50
The cls at the start is a throw back to classic days and win2k refresh, not required for pro.

your switching the backdrop on and off within your code, once at the top and off again prior to your main loop.

your missing sync statements prior to the end of your loops

your adding clear screen elements to your loops, which is effectively another clear and sync of the screen.

dont try to add any gosubs for now, just align it all so its procedural to get it working.

try to be neater with your variables and declare them in one area to make life easier.

Here is a revised snippet to the above I made for you earlier.
Notice Ive changed the start button to enter or return.

And now Ive added a button trapping method to allow to see the result of the bullet sprite appearing without a blue backdrop issue. We are using scancodes and only capturing one keypress, not rapid fire.



The bullet does not offset, rotate or move away from the players sprite but you get the mechanics of what im trying to show you in action.


Your seeing the blue background if the backdrop has not been declared off which is lines 19 and 20 in your revised code.

Anyway hopefully this example will make it clearer for you.





Login to post a reply

Server time is: 2025-08-09 02:15:30
Your offset time is: 2025-08-09 02:15:30