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.

DarkBASIC Professional Discussion / Problem with moving background?

Author
Message
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 25th Oct 2013 22:59
Hi, I am in need of some help!
I'll post a video containing the problem, but the description is that: I've coded a background to a 2D game that's meant to change into two separate backgrounds, and the one one the left will slowly inch toward the end to then change into the rest of the next background. Now, I managed to do this, but when the first background changes, the game freezes up on me. I'll post the codes I've used here as well, so do anyone have any ideas or solutions?

Here is my whole game code



Thanks for answers

Attachments

Login to view attachments
Broken_Code
14
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 28th Oct 2013 20:24
First, learn about for-loops, they're awesome!
For example:
This:

is the same as this:


For-loops can save you a lot of typing!
As for your Problem, I watched your Video but I'm not sure what the Problem is? Does it Crash with a message or does it just hang?
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 28th Oct 2013 21:24 Edited at: 28th Oct 2013 21:25
Thanks Broken_code
Quote: "what the Problem is? Does it Crash with a message or does it just hang?"

The problem is that when the picture of the factory come, my game starts to hang. No error message come. Do you have any ideas about the problem?

Thanks again for your answer
Broken_Code
14
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 28th Oct 2013 21:53 Edited at: 28th Oct 2013 22:05
OK, I think the Problem is in here:


When the code gets here is XJ still 512?
There is no sync Statement in here so as Long as the code is here the Screen wont update!

Here\'s how I would write that:

This way it doesn\'t matter what the value of XJ is!
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 28th Oct 2013 22:00 Edited at: 28th Oct 2013 22:08
Thanks, I will check it out as soon as possible, and I think the for-loop will get rid of my problem
Broken_Code
14
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 28th Oct 2013 22:09
Here's how I would write that section:



I'm sure there are a Million and one better way to write it but this is simple and should work.

Good luck!

P.S. Don't Forget to Show us your game when your done!
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 29th Oct 2013 04:06
The best way to handle this is to treat the camera or viewing area as a position in the world which offset everything.

If we move the camera (2d position) we alter it's position in the world. Now when it comes to other things in the world, you set them up as normally, any position you want. But when it comes to drawing you offset that position by the camera's world position. So...

draw position = position - camera world position

Here's an example of this (with bounds so it doesn't go move forever):


What is cool about this method is it's easy to change the way things move or how there positioned. So say if you wanted the background to move slower than things in front of it. You can do this:

draw position = position - (camera world position/factor)

An example of this is:


"Get in the Van!" - Van B
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 30th Oct 2013 22:27
Thanks for your help
I have tried to use your code-example Broken_code, but my game still hangs. I tried to experiment with the for-step-loop, and then my game stopped to hang But now I have other problems, my frame rate drop from 60 to 38/40 after the image has changed. I have attached a video

Here is my new code

Attachments

Login to view attachments
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 30th Oct 2013 23:04
I really don't understand what your trying to achieve here. Cause both video have on collision half of the next background appear and the first background slowly move out the way until the second full background appears.

Also:
Quote: "
for i=0 to -512 step -1
Paste image 222,512,0
Paste image 224,XJ,0
next i
"


Why are you pasting these 2 images 512 times in a single frame at the same position? Also when START = 0, XK will still be is less than -512 so it will keep pasting those 2 images 512 times a frame!

"Get in the Van!" - Van B
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 31st Oct 2013 11:11 Edited at: 31st Oct 2013 11:14
Quote: "I really don't understand what your trying to achieve here"


In the game me and my friend is creating, we're adding a sort of DOA effect where one character can be knocked off the map you're on. Though, instead of having the second character pop out of no-where on the second map, we're cutting the screen in to and creating the effect that the two characters are on different parts of the map, and one has to go to the other
Broken_Code
14
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 31st Oct 2013 11:41 Edited at: 31st Oct 2013 11:45
@ Sasuke:
The effect can be seen in the vid on the first post! I didn't immediately get it either...

@WAKS:
I think you've misunderstood what I was trying to do!
Here's some Explanation:



However in your code:


I don't want to be patronising but there is a quite difference here...

[EDIT] Clarity
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 31st Oct 2013 12:10
Thanks Broken_code

Quote: "I think you've misunderstood what I was trying to do!"


I am sorry if I have misunderstood everything. I am a beginner in DarkBasic pro therefore I do a lot of faults I tried your code-example, but I recieved a big problem. After my background move was finished, it would't stop, and it continued to move out of the screen, and the original background repeat the whole process again Therefore I tried to experiment with connect your code idea into my original code

Quote: "if XK < -512 //I don't know what XK is ???"


XK = 0

Quote: " XJ = 0 //I don't know what XK is ???"


XJ = 512

Quote: " //NO SYNC FUNCTION!!! "


I tried the sync command, but when sync is on, and the moving background process is done. Then the left side picture becomes delete and the blue standard background appears

Thank you for using your time to help me
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 31st Oct 2013 12:13 Edited at: 31st Oct 2013 12:15
Quote: "
for i=0 to -512 step -1 //This says 'make i go from 0 to -512 in steps of -1'
Paste image 223,i,0 //This pastes this Image 233 at (x,y)=(i,0), i changes every Loop of the for-loop so the Image will be pasted
//in a slightly different Position each for-Loop and appear to move accross the Screen!
Paste image 222,512,0 //This pastes the other Image, nothing interesting!
sync //This is very important, this draws everything to the Screen, without this command nothing will appear on screen!
next i //This moves to the next i value (i=i+step)
"


The problem here is image 222 is being pasted in the same place 512 times for no reason, the loop speed is very depended fps, they'll be a huge delay(depended on fps how long) before anything else can update that's outside of the loop, everything after it won't draw unless you have an active backdrop.

Quote: "In the game me and my friend is creating, we're adding a sort of DOA effect where one character can be knocked off the map you're on. Though, instead of having the second character pop out of no-where on the second map, we're cutting the screen in to and creating the effect that the two characters are on different parts of the map, and one has to go to the other "


Ahh now this all makes sense! What I want to know is how the split screen works, so if two players are on different maps, do you want there background to move aswell based on there location on that map. And if the two player meets the view un-splits, something like that?

If I know exactly what your trying to do then I(we) know the best course of action to take

"Get in the Van!" - Van B
Broken_Code
14
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 31st Oct 2013 12:59
Quote: "Ahh now this all makes sense! What I want to know is how the split screen works, so if two players are on different maps, do you want there background to move aswell based on there location on that map. And if the two player meets the view un-splits, something like that?

If I know exactly what your trying to do then I(we) know the best course of action to take "


Ah, I'd assumed it was a cut-scene sort of Thing?! Is that right?


Quote: "I am sorry if I have misunderstood everything. I am a beginner in DarkBasic pro therefore I do a lot of faults "


np, I probably didn't explain it very well! Everyone's a beginner at some Point, even EVOLVED!

Quote: "I tried the sync command, but when sync is on, and the moving background process is done. Then the left side picture becomes delete and the blue standard background appears "


The sync command is Needed to draw everything to the Screen, so if it is left out of the Loop None of the changes will appear on Screen!
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 31st Oct 2013 13:18
@ Sasuke

Quote: "Ahh now this all makes sense! What I want to know is how the split screen works, so if two players are on different maps, do you want there background to move aswell based on there location on that map. And if the two player meets the view un-splits, something like that?

If I know exactly what your trying to do then I(we) know the best course of action to take."


Yes, that's what I'd like to do, could you help with that?
WAKS
11
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 31st Oct 2013 13:50 Edited at: 31st Oct 2013 14:03
@ Broken_code

Quote: "P.S. Don't Forget to Show us your game when your done!"


Afterward when we have worked a little bit more with the game I will post it on the showcase or work in progress page on TGC

@ Sasuke

Quote: "The problem here is image 222 is being pasted in the same place 512 times for no reason, the loop speed is very depended fps, they'll be a huge delay(depended on fps how long) before anything else can update that's outside of the loop, everything after it won't draw unless you have an active backdrop."


yeah, thanks it fix my fps drop
Now i have no problems with my moving background idea, and I will thank again for all the help I have received

Login to post a reply

Server time is: 2025-05-16 18:22:31
Your offset time is: 2025-05-16 18:22:31