Hello guys, I hope you are all well!
I am creating a game in Visual Studio using picture box's, but I cannot for the life of me figure out how I can have a nice picture in the background, as when I do put one in there it is constantly redrawn everytime the game refreshes and this make it impossible to play as it slows almost to a halt. My question for you pro's is, can I set the background image of the panel to never refresh?
With the amount of different things Visual Studio can do, I am sure there must be a way to achieve this simple task?
I have tried everything but I cannot figure it out, if anyone can help me I would be greatly appreciative!
Many thanks to you all!!
Cheers!!!!!!
Loading
RayPosted Jan 5, 2011, 4:04 PM
Thanks again Frogleg!
FroglegPosted Jan 5, 2011, 3:44 PM
Points to you for the effort you put into your project
RayPosted Jan 5, 2011, 6:24 AM
I know my code is really rough and I didnt really know much about file IO until attempting this, but it's great having all these tips from you, I can't wait to see what the difference is with your alterations! I have looked into XNA I was seriously considering downloading and installiing it and teaching myself the code so I could make simple game, it sounds like it could be great fun, and I am alwasy getting loads of ideas!
Frogleg, one thing I was meant to ask you was, as I am using enumeration on the socring in the Enemy class, how can I get the mothership and destroyer to increment in value every time they are killed, so if one is worth 100 points then everytime it is killed it is worth 110, 120, 130 etc... And I was wondering how I could alwasy save the highscore to the highscore box? Are these things that are too difficult to do?
Frogleg I owe you for all your help and assistance!
Thank you!
FroglegPosted Jan 5, 2011, 1:18 AM
I did cut out a bit of excess code - remove all "GamePanel.Refresh();:
When you save a game in Mydocuments you should create a folder with game name.
When I saved and loaded a game there was heaps of txt files (of my own) to sort through - and maybe give the files a ".sav" extension rather than ".txt"
Considering the amount of pictueboxes moving around it is(the game) running reasonably well
Also have a look at XNA which is a free purpose built for games sofware that integrates with C#- You can use 2d or 3d models
RayPosted Jan 4, 2011, 11:31 AM
Thanks again for your time with this!!!!!
Ray
FroglegPosted Jan 4, 2011, 8:45 AM
I added a timer to the project and set interval to 10
private void timer1_Tick(object sender, EventArgs e)//paste this above GamePanel_Paint and comment out as below
{
//private void GamePanel_Paint(object sender, PaintEventArgs e)//this is the game loop, it controls what happens when the game is running this is where objects update and refreshes
You will have to comment out
//this.GamePanel.Paint += new System.Windows.Forms.PaintEventHandler(this.GamePanel_Paint);
in MainScreenDesigner.cs
Also check Mercurianbullet.jpg as the one I d/loaded was corrupt
I'll take a look at the code again tomorrow
RayPosted Jan 4, 2011, 6:10 AM
Thanks again, if you like you can email the result to me at [email protected] if that is any easier for you? Just a thought.
Anyway many thanks again!!!!
Cheers!
FroglegPosted Jan 4, 2011, 2:47 AM
RayPosted Jan 3, 2011, 4:28 PM
Frogleg, I appreciate your help with this thanks for the code!!! I just think I am not experienced enough to do things like this just yet.
Thanks a lot!!
Ray
FroglegPosted Jan 3, 2011, 3:11 PM
You have quite a few pictureboxes floating around which will slow your code
Without the whole project I could not test my proposal
1. Create a double buffer panel to stop flickering
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace SpaceInvaders
{
class DoubleBufferPanel : Panel
{
public DoubleBufferPanel()
{
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();
}
}
}
Add a new class to your project, hit build - then in your toolbox there will be a doubleBufferedPanel. swap this with your gamepanel
Add your background image to your resources and also create using mspaint a red image same size as panel - add this to your resources
to implement
doubleBufferPanel1.BackgroundImage = SpaceInvaders.Properties.Resources.OrigImage;//your original image
doubleBufferPanel1.BackgroundImage = SpaceInvaders.Properties.Resources.Redjpg;//the new image
You are now swapping images instead of painting panel background
Hopefully you will not need panel refresh
RayPosted Jan 3, 2011, 12:17 PM
I have attached my code, I hope I have done it correctly!
Many many thanks!!!
Ray
FroglegPosted Jan 2, 2011, 6:30 PM