|
Hi all,
Continuing the development of my 2D game for school, I encountered a new problem that is killing me.
When I draw 1 sprite on top of the other, the one on top starts flickering. I googled for a while and found that doublebuffering would solve the problem. However, setting the styles:
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);
does not work, neither does DoubleBuffered = true, and at one point I wrote a simpel double buffering mechanism myself, which also did not solve the problem. My program works as follows:
In the constructor, a Graphics object is created using CreateGraphics(). Then, as soon as a Timer fires the Tick event, sprite positions are updated, and the Draw() method is called of the sprite, passing in the Graphics object created in the constructor. I did not override OnPaint.
Any idea's on how to fix this?
Thanks!
|
|
|
|
|
Hi,
what is the timer's interval?
if anything less than 15, you'd better read my timers article first.
Normally painting occurs in a paint handler, that's either the OnPaint method or some
delegate you add to the Paint event. If you want a timer to cause a repaint, have it
invoke the Invalidate() method of the Control/Form.
If you have many Controls of a Form, double buffering will improve but not solve things.
For gaming (and many other apps) I prefer to have the activitly going on in a Panel,
make that one double buffered, and not have any controls associated with that Panel.
The timer then only has to invalidate that Panel, so no time gets wasted in repainting
the other Controls.
FYI: you can invalidate part of a Control by using some of its overloads.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
when i built a juggling simulator I ran into similar problems. In the end i decided that rather than having separate images for each object I would create a bitmap image in my application and stick that on screen. Given that most of my image was a black background this seemed the most efficient method for me.
YMMV
Russ
|
|
|
|
|
How much of the screen are you redrawing? Only redraw portions that require an update. See this article for a bunch of the settings required.
http://www.codeproject.com/csharp/DoubleBuffering.asp?df=100&forumid=262139&exp=0&select=1394270
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
I am trying to export multiple crystal reports to a single destination PDF.
I can do export a single file to a single PDF like this:
ReportDoc.Load(rptname);
ReportDoc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
ReportDoc.ExportOptions.DestinationOptions = ReportDiskDestination;
ReportDoc.Export();
But, I am not able to export multiple report to a single export file. It overwrites the file and the earlier report(s) are lost.
Please help!
|
|
|
|
|
Hi All,
I've set my ToolStrip's Text property [1]. However, .Net 2.0 refuses to display it. Any ideas on how to get this control to disply the text? As usual, the documentation does not mention the property is not honored, or offer a work around...
Jeff
[1] ToolStrip Properties[^]
|
|
|
|
|
Please set DisplayStyle= ImageAndText
Also you can right click on tool strip and add a label to it and then set text to that label.
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
I work on a class that handles the a tcp-connection but now i discovered a problem with my data-handling and cant solve it =/
First some Informations:
The Socket-class provides the Async-Methodes BeginReceive and EndReceive to receive the data over the socket.
When i call BeginReceive then another Methode will automatically raise.
connSocket.BeginReceive( mainBuffer_, 0, mainBuffer_.Length, SocketFlags.None, out socketError_, new AsyncCallback( receivedata ), connSocket ); In this case the methode "receivedata" will raise when data are available. In this methode "receivedata" do i fetch the data from the socket and save it a Queue, after that i start a second thread wich process the data from the queue.
private SocketError socketError;
private volatile byte[] mainBuffer;
private volatile int receivedDataSize;
private volatile Thread processingThread;
private volatile AutoResetEvent autoResetEvent;
private volatile Queue<List<byte>> receivedDataQueue;
...
private void receiveData( IAsyncResult aSyncResult ) {
try {
Socket connSocket = ( Socket ) aSyncResult.AsyncState;
receivedDataSize = connSocket.EndReceive( aSyncResult, out socketFehler_ );
if( receivedDataSize > 0 ) {
if( receivedDataSize != connSocket_.ReceiveBufferSize ) {
byte[] tmpBuffer = new byte[ receivedDataSize ];
Array.Copy( mainBuffer, tmpBuffer, receivedDataSize );
receivedDataQueue.Enqueue( new List<byte>( tmpEingangsPuffer ) );
}
else {
receivedDataQueue.Enqueue( new List<byte>( mainBuffer ) );
}
if( ( socketClosed == false ) &&
( ( processingThread == null ) || ( processingThread.IsAlive == false ) ) ) {
processingThread = new Thread( new ThreadStart( empfangsDatenVerarbeitung_ThreadMethode ) );
processingThread.IsBackground = true;
processingThread.Start();
}
autoResetEvent_.Set();
}
else {
closeConnection();
}
if( socketClosed == false ) {
Array.Clear( mainBuffer, 0, mainBuffer.Length );
connSocket.BeginReceive( mainBuffer, 0, mainBuffer.Length, SocketFlags.None, out socketFehler_, new AsyncCallback( receiveData ), connSocket );
}
}
catch( SocketException ) {
closeConnection();
}
catch( ThreadStateException ) {
closeConnection();
}
catch( ObjectDisposedException ) { } The second thread execute the following Methode
private void empfangsDatenVerarbeitung_ThreadMethode() {
while( socketClosed == false ) {
if( receivedDataQueue.Count > 0 ) {
while( receivedDataQueue.Count != 0 ) {
}
}
autoResetEvent_.WaitOne();
} -------------------------------------------------------
OK, it looks fine but the method "receiveData" wich should be raised automatically when data are available doesnt raise everytime. After a minute it starts to stuck =/...my question is now...
Is there something that i do wrong with the threading ?
|
|
|
|
|
i'm not sure, but i think that Thread.IsAlive is a bit dangerous...
msdn says about Thread.IsAlive : "true if this thread has been started and has not terminated normally or aborted otherwise false" so if an exception comes up in your dataprocessing you have a autoResetEvent that signals something and nobody listening.
-- modified at 5:01 Thursday 29th November, 2007
never mind.. Thread.IsAlive does exactliy what it should
you could put the stuff into a console application and do some Console.WriteLines to find out where it actually stops working..
|
|
|
|
|
Hello,
I wish to incorporate some assembly security attributes to my class library. So I add something like this to my class library namespace:
[assembly:System.Net.SocketPermission(SecurityAction.RequestMinimum)]
namespace olapWeb_Controls
{
So on and so forth. Yet I have many classes in my class library - all of them reference the namespace. Apparently I can add permission by simple adding the directives to just one of the classes - but I would rather I added them one central place, rather than in just one class (which might get changed by someone else than me). Adding the same permissions to every single class seems like overkill. What should my best practice be?
Many thanks,
Morten,
Denmark
|
|
|
|
|
How I can add a new created data row in data table...?
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
datatablename.Rows.Add(colone,coltow,colthree,......);
Thaer
|
|
|
|
|
Thx for reply.
Suppose I have 10 columns and I want to pass only three values then what to do.?
Also how to manage the identity column of the table....?
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
Where to pass column name and data type..?
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
DataColumn col = table.Columns.Add();
col.ColumnName = "name";
col.DataType = type;
DataRow row = datatablename.NewRow();
row["columnname"] = value;
|
|
|
|
|
|
hi all
i build activex control by using C#.Net but i wount to preview any KeyDown on any control in new control .
the new control is 2 control is the label and textbox ,
i wount to preview any key down on textbox or on label i means any way key is down on any control on my new control .
how i can have any key is down on this control
thank for any body hellp me
Thaer
|
|
|
|
|
Hello together,
is it possible to display into a DataGridViewImageColumn different pictures, for different rows?
I tried it already this way:
looping on each row, getting the DataGridViewImageCell and set the Value-Property to a
new System.Drawing.Bitmap
But it don't work
Thanks for help
|
|
|
|
|
yes you can add columns by datatype image
go to edit columns to thr datagridview and add new column by type DataGridViewImageColumn
welcom mr
Thaer
|
|
|
|
|
Sorry, i think you missunderstand my question.
i need an ImageColumn and in this column, the rows have different images.
For example
Row 1 has a "doc.jpg"
Row 2 has a "mail.jpg"
Row 3 has a "fax.jpg"
Row 4 has a "mail.jpg"
But thanks for help
|
|
|
|
|
Use this
Icon treeIcon = new Icon(Path + "Images\\History.ico");
DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
iconColumn.Image = treeIcon.ToBitmap();
iconColumn.Name = "ColHistory";
iconColumn.HeaderText = "History";
DataGridView1.Columns.Insert(12, iconColumn);
//Where 12 is location of column number
Regards
Pankaj Joshi
If you want to shape your dreams into reality, please wake-up...
|
|
|
|
|
Hello Everyone,
Can anybody let me know how to run the CSharp program in Dos window of .NET Framework
|
|
|
|
|
what do you mean by CSharp Program?????
Nothing is Impossible. Even impossible spells "i m possible"
|
|
|
|
|
Do you mean a Console Project?
|
|
|
|
|
Helloooooooooooooooooooo
Yes i mean a console app.
|
|
|
|