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! / Off screen problem

Author
Message
Bankzy10
15
Years of Service
User Offline
Joined: 29th Jan 2009
Location: Planet DarkBasic - Learning the tricks
Posted: 6th Jun 2009 18:30
I have a spaceship that goes off the screen and was wondering how I stopped it from leaving the screen. The problem is only with it going off the top and bottom of the screen (it doesn't move left or right). How can I stop it? My spaceship is 90 by 37 and is located on the left side of the screen (its the background that scrolls to allow it to look like its moving right).

Thanks in advance, Bankzy10 =]
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 6th Jun 2009 19:53
You just check to see if the spaceship is beyond the limits before you show it. If it is outside of the limits you change the coordinates to within the limits.



Bankzy10
15
Years of Service
User Offline
Joined: 29th Jan 2009
Location: Planet DarkBasic - Learning the tricks
Posted: 6th Jun 2009 22:02 Edited at: 8th Jun 2009 01:28
How would you do it with keyboard inputs though as that done with where the mouse cursor is. Is there no statment for something like this:

If SPRITE NUMBER < 640, 0 THEN move back 37 (as the image is 37 pixels high).

640 Pixels
____________________
-/------------------|
--------------------| 4
-|--/___Spaceship---| 8
/-|/----------------| 0
--------------------| Pixels
-/------------------|
____________________|

The spaceship doesn't move to the right or left. It moves up and down. The ship is 90 X 37 pixels if that helps. It all works by Keyboard inputs - the up and down arrow buttons.
vidmouse
15
Years of Service
User Offline
Joined: 28th Apr 2009
Location:
Posted: 15th Jun 2009 22:10
Is this topic still live? My posts are delayed b/c I'm a noobie poster. It seems to me that you essentially have it, except that you need to check if the sprite location, not the sprite number is less than 0 or greater than 640:



Vidmouse's Software: http://www.freewebs.com/vidmouse/software.htm
Bankzy10
15
Years of Service
User Offline
Joined: 29th Jan 2009
Location: Planet DarkBasic - Learning the tricks
Posted: 18th Jun 2009 23:59 Edited at: 19th Jun 2009 00:28
So I would put it like this into my code?



Is that right? Or have I messed up with something?

EDIT: I have tried it and it works. The only problem is that it lags the game quiet abit, where when you hit the top and bottom of the screen it freezes for a second or so. It has a sync after that code, but still has the lag issue. Is there anything else I can do? Maybe run it from a sub?

Thanks, Bankzy10
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Jun 2009 02:55
It's hard to say without more code. If you have a DO/LOOP exactly like your last code snip that may be the cause because there is no way to leave the DO/LOOP. If the SYNC is outside of that DO/LOOP it'll never SYNC again.

Bankzy10
15
Years of Service
User Offline
Joined: 29th Jan 2009
Location: Planet DarkBasic - Learning the tricks
Posted: 19th Jun 2009 11:35
This is my entire do loop that the code is located in. At the beginning the code is for my scrolling background, then my scoring and life text and then its the code from above. As you can see, it has the sync of it.



If had a little fiddle around with it, but it's still doing the same - any suggestions?

Thanks, Bankzy10
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Jun 2009 12:27
You should put the SYNC at the bottom just before LOOP. Putting it there makes sure anything in the DO/LOOP will be SYNCed at the same time. The text size and the color can be put outside of the DO/LOOP (since they don't change) and you only need one of each. COPY BITMAP may be causing lag too. Since you're just copying the bitmap of a pasted image you could just paste the image to bitmap zero and avoid switching screens and copying the bitmap. Hopefully that'll de-lag your game.

Login to post a reply

Server time is: 2024-07-27 00:36:21
Your offset time is: 2024-07-27 00:36:21