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 / Flickering Screen after integrating Sprites

Author
Message
DBProUser
15
Years of Service
User Offline
Joined: 28th Oct 2010
Location:
Posted: 22nd Nov 2010 17:57 Edited at: 22nd Nov 2010 17:59
Hallo,

i have made a little 2D Game and it work really fine.

But now i wanted to put some Specials in it. I Thought about the Hero is throwing a Stone, to get Bananas from a Ape on a tree

After inserting some code, i get The Stone flying, but the Screen is terribly flickering that i get a headache. The Screen is flickering because it is changing very fast between the 3D-Blue-Background and my 2D-Animated Background. It just Stops Flickering after i throw a Stone, and Sometimes when the Monkey is Jumping (So i guess it has something to do with redrawing the Screen, but i dont Know how to do that, after trying so many variants without a Success)

So sorry for annoying you, but it would be great if i can find a Solution with your help.

Here is a Code Snippet



Thanks for help
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 22nd Nov 2010 18:20 Edited at: 22nd Nov 2010 18:21
A few suggestions...

Your ThrowStone function should not load and delete the stone.png bitmap and image every time you call the function, this is making your sprite flash. Load the graphics only ONCE at the beginning of your program

I like to keep ALL of my keyboard inputs during a game in one area, not in several different functions

use only one sync, at the bottom of the main loop. If you couldn't see the sprite with only your main loop sync, then there are logic problems in your code that need to be fixed, more example code would help
DBProUser
15
Years of Service
User Offline
Joined: 28th Oct 2010
Location:
Posted: 22nd Nov 2010 18:47
There are a Lot of Lines (ca. 1100) So it would be really tough to look through all the lines.

Here is my Main Loop, maybe it helps



Now the Picture is Loading at the beginning of the Program like the other Pictures, but unfortunatly the result is still the same

BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 22nd Nov 2010 19:12
When you have an animated object in your game, you want a key press to set a variable such as throwflag=1, then in another function...
if throwflag=1 (then update animation, move object a little, etc)
when you are done with the animation, then reset throwflag=0.

What you don't want to do is wait in a function using repeat..until, while your animation finishes, pausing your entire game until it is done.

to review...
1)remove the repeat..until from your throwstone function
2)spacekey will set a flag variable like throwflag=1
3)Another function will update the animation if throwflag=1
4)if you want to have more than one stone, use arrays to keep track of all the objects you want animated on the screen, and update their position,etc. in the arrays, this works great.
DBProUser
15
Years of Service
User Offline
Joined: 28th Oct 2010
Location:
Posted: 22nd Nov 2010 19:21 Edited at: 22nd Nov 2010 19:21
Thanks a lot for your suggestions, i will try it out.

in the meantime i changed the Sprite to an Image. This works fine, without the flickering. But i dont want to use a Image, because Sprites are far more flexibel



So back to the drawing-Board
BillR
23
Years of Service
User Offline
Joined: 19th Mar 2003
Location: United States
Posted: 22nd Nov 2010 22:35 Edited at: 23rd Nov 2010 03:31
Here is some code showing flags and arrays being used
to throw multiple rocks
Spacebar throws rock sprites

DBProUser
15
Years of Service
User Offline
Joined: 28th Oct 2010
Location:
Posted: 23rd Nov 2010 11:21 Edited at: 23rd Nov 2010 11:22
Sorry for not answering earlier, but i think there is a little Time-Difference between the US and Germany (6 to 12 hours, it depends where)


Thank you for the Code-Example and for your help yesterday. I will try it out later, when i am at Home. Till then.
Indicium
18
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 24th Nov 2010 21:42
If there is a CLS command in your main game loop, remove it when using sprites.

Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 30th Nov 2010 13:35
I didn't see a "sync on" command. Without that, you will get a flicker with sprites.

The fastest code is the code never written.

Login to post a reply

Server time is: 2026-07-21 13:38:40
Your offset time is: 2026-07-21 13:38:40