Maybe you should space out your code in to bits your brain can handle.
Anyway to learn Win32 in a way that is game oriented? Because at the moment i find it makes no fucking sense however i approach it and it's causing problems with my game's code since I cant add my textbox in the game without figuring this out.
[QUOTE=chaz13;32047671]I've got a fairly simple problem, I'm trying to draw a sort of health/progress bar by rendering part of a sprite.
[code]spriteBatch.Draw(barFront, player.isoPos + new Vector2(-32, 35) - viewPos,
new Rectangle(0, 0, 48*(pickupCount/treeController[controlId].trees[treeId].pickupTime), 7),
Color.White, 0f, Vector2.Zero, new Vector2(1, 1), SpriteEffects.None, 1f);[/code]
For some reason it doesn't draw it at all until pickupCount is equal to pickupTime, which is only for a split second. What have I done wrong?[/QUOTE]
Good golly that's a long slice of code.
Like Jookia said, I would space out the thinking into other variables and places.
Here's an example from my stuff:
[code]
if (isVisible)
{
if (animation == null)
{
sb.Draw(texture, position, null, color, rotation, origin, scale, SpriteEffects.None, layerDepth);
}
else
{
sb.Draw(texture, position, animation.GetCurrentFrame(), color, rotation, origin, 1, SpriteEffects.None, layerDepth);
}
}[/code]
Considering the error, I think you might have a problem here:
[code]new Rectangle(0, 0, 48*(pickupCount/treeController[controlId].trees[treeId].pickupTime), 7)[/code]
Rectangle [B]only accepts int[/B] as its argument datatypes -- if pickupCount/treeController[blahblahblah] is ever less than one then your width may be 0 due to precision issues.
hey, im trying to make a flash remake of the racing game wipeout. I've got (relatively) realistic acceleration and handling for the player/car/ship thing done, all i need is for the player/car/ship thing to collide with the sides of the track and take damage.
i know how im going to do the damage modelling and bouncing physics ect, i just need collision detection. for that i want to use gskinners shape based collision, but i cant get the class to work.
I've dissected all of the code and it is completely eluding me as to how to get the damned thing to work.
Can someone take a look at it, and tell me what code to use to detect collisions between the MCs mainCar (the player/car/ship thing) and trackOutline (no prizes for that one). I'm afraid I'm missing something basic here.
[URL="http://gskinner.com/blog/archives/2005/10/source_code_sha.html"]http://gskinner.com/blog/archives/2005/10/source_code_sha.html[/URL]
just talk as if your talking to someone who is clueless, explain how the class works ect.
i will mention the person who helps me solve this problem in the credits for the release
Hey, i've been attempting to make games for a while now and i've had moderate success, the main problem i have is designing the programme itself. How to organise things to make it efficient and easy to use.
Does anyone have any tips/books/tutorials on the subject to help me?
[QUOTE=Bambo.;32058160]Hey, i've been attempting to make games for a while now and i've had moderate success, the main problem i have is designing the programme itself. How to organise things to make it efficient and easy to use.
Does anyone have any tips/books/tutorials on the subject to help me?[/QUOTE]
So you are saying you want to pull meaning from the chaos? You are asking, isn't there some [URL="http://www.amazon.com/First-Design-Patterns-Elisabeth-Freeman/dp/0596007124/ref=sr_1_2?ie=UTF8&qid=1314890985&sr=8-2"]pattern[/URL] to this mess?
I found that book to be an awesome resource, easy to pick up and read.
Tips wise, static classes are amazing. I tried and tried to find out if there were downsides to using them, but I couldn't find anything major.
Just look at this black magic:
[code] public static class MouseManager
{
public static MouseState MState, oldMState;
public static void Update()
{
oldMState = MState;
MState = Mouse.GetState();
}
}[/code]
Elsewhere:
[code]
if (MouseManager.MState.ScrollWheelValue < prevScrollValue)
{
//Do Stuff
prevScrollValue = MouseManager.MState.ScrollWheelValue;
}[/code]
You can access static methods and variables from anywhere in the same namespace just by using the type.
For some reason my game is crashing on App.Display() does anyone know what could be causing this?
[QUOTE=Richy19;32058762]For some reason my game is crashing on App.Display() does anyone know what could be causing this?[/QUOTE]
It's difficult to find the cause unless you show some code.
[QUOTE=sim642;32059039]It's difficult to find the cause unless you show some code.[/QUOTE]
There isnt really much to show tho, I create the window as yu should, I draw sprites and font to it, and then display the stuff at wich point the program closes
[QUOTE=Richy19;32059303]There isnt really much to show tho, I create the window as yu should, I draw sprites and font to it, and then display the stuff at wich point the program closes[/QUOTE]
Are you wrapping your rendering in a loop so it just doesn't display and turn off?
[QUOTE=awfa3;32059612]Are you wrapping your rendering in a loop so it just doesn't display and turn off?[/QUOTE]
heeh yea, I have used SFML before and it worked fine, it seems its started when i moved to linux
[editline]1st September 2011[/editline]
hmm it seems its when I render the main menu so it must be something to do with the text.
[editline]1st September 2011[/editline]
Aha its when I set the origin of the text, I think im doing it right but can someone check?
[code]TitleText.SetOrigin(TitleText.GetRect().Width / 2, TitleText.GetRect().Height / 2);
NewGameText.SetOrigin(NewGameText.GetRect().Width / 2, NewGameText.GetRect().Height / 2);
OptionsText.SetOrigin(OptionsText.GetRect().Width / 2, OptionsText.GetRect().Height / 2);
QuitText.SetOrigin(QuitText.GetRect().Width / 2, QuitText.GetRect().Height / 2);
[/code]
[QUOTE=chaz13;32047671]I've got a fairly simple problem, I'm trying to draw a sort of health/progress bar by rendering part of a sprite.
[code]spriteBatch.Draw(barFront, player.isoPos + new Vector2(-32, 35) - viewPos,
new Rectangle(0, 0, 48*(pickupCount/treeController[controlId].trees[treeId].pickupTime), 7),
Color.White, 0f, Vector2.Zero, new Vector2(1, 1), SpriteEffects.None, 1f);[/code]
For some reason it doesn't draw it at all until pickupCount is equal to pickupTime, which is only for a split second. What have I done wrong?[/QUOTE]
try this:
[code]
Rectangle rect = new Rectangle(0, 0, (int)(48f * (pickupCount / (float)treeController[controlId].trees[treeId].pickupTime)), 7)
spriteBatch.Draw(barFront, player.isoPos + new Vector2(-32, 35) - viewPos,
rect, Color.White, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 1f);
[/code]
[QUOTE=Richy19;32059656]heeh yea, I have used SFML before and it worked fine, it seems its started when i moved to linux
[editline]1st September 2011[/editline]
hmm it seems its when I render the main menu so it must be something to do with the text.
[editline]1st September 2011[/editline]
Aha its when I set the origin of the text, I think im doing it right but can someone check?
[code]TitleText.SetOrigin(TitleText.GetRect().Width / 2, TitleText.GetRect().Height / 2);
NewGameText.SetOrigin(NewGameText.GetRect().Width / 2, NewGameText.GetRect().Height / 2);
OptionsText.SetOrigin(OptionsText.GetRect().Width / 2, OptionsText.GetRect().Height / 2);
QuitText.SetOrigin(QuitText.GetRect().Width / 2, QuitText.GetRect().Height / 2);
[/code][/QUOTE]
Its not when I set the origin, its when I get the rect
Richy19, use variables. Don't cram everything in to one line otherwise the debugger won't be able to tell you where it fails.
[QUOTE=NovembrDobby;32060100]try this:
[code]
Rectangle rect = new Rectangle(0, 0, (int)(48f * (pickupCount / (float)treeController[controlId].trees[treeId].pickupTime)), 7)
spriteBatch.Draw(barFront, player.isoPos + new Vector2(-32, 35) - viewPos,
rect, Color.White, 0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 1f);
[/code][/QUOTE]
That works perfectly! Thank you :smile:
I'm trying my hand at making a very simple windows forum game, and I wanted to know how I could help optimize my horribly shitty inefficient code.
[csharp]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace bombgame
{
public partial class Form1 : Form
{
double timerString = 30;
string number1 = "0";
string number2 = "0";
string number3 = "0";
string number4 = "0";
string number5 = "0";
int currentInputNumber = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
currentInputNumber += 1;
if (currentInputNumber == 1)
{
number1 = "1";
}
if (currentInputNumber == 2)
{
number2 = "1";
}
if (currentInputNumber == 3)
{
number3 = "1";
}
if (currentInputNumber == 4)
{
number4 = "1";
}
if (currentInputNumber == 5)
{
number5 = "1";
}
inputwindow.Text = number1 + number2 + number3 + number4 + number5;
}
}
}
[/csharp]
Use a switch statement.
[QUOTE=Jookia;32068188]Use a switch statement.[/QUOTE]
Would there be an easy way to preform that large switch for each of the 5 numbers?
I guess, what does your code do?
[QUOTE=Jookia;32070125]I guess, what does your code do?[/QUOTE]
Essentially, I'm trying for a graphical re-iteration of the classic guess the number, with the added fun of a live explosive on a timer.
[img]http://i.imgur.com/WMvMi.png[/img]
[cpp] LPWSTR* pathData = 0;
HRESULT result = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL,
pathData);[/cpp]
Can somebody tell me why that throws an exception (somehow, it's C. MSVC is weird)?
[QUOTE=Jookia;32071763][cpp] LPWSTR* pathData = 0;
HRESULT result = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL,
pathData);[/cpp]
Can somebody tell me why that throws an exception (somehow, it's C. MSVC is weird)?[/QUOTE]
You're probably getting the access violation exception as SHGetKnownFolderPath tries to dereference that null pointer you passed it.
You probably meant to do this:
[cpp]
LPWSTR pathData = 0;
HRESULT result = SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &pathData);
if(result == S_OK)
{
// use pathData, then free with CoTaskMemFree
}
[/cpp]
Oh, I forgot that LPWSTR was a pointer. I thought it was a type for a pointer to use.
[QUOTE=Mr. Smartass;32067828]I'm trying my hand at making a very simple windows forum game, and I wanted to know how I could help optimize my horribly shitty inefficient code.[/QUOTE]
Something like this?
[code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace bombgame
{
public partial class Form1 : Form
{
double timerString = 30;
List<int> keyedNumbers = new List<int>(5);
int currentKeyedNum = 0;
public Form1()
{
InitializeComponent();
for(int i = 0; i < 5; i++)
keyedNumbers.Add(0);
}
private void pressButton(int btnNum)
{
currentKeyedNum++;
//loop around and start entering numbers at the first index again if they have entered 5 already
currentKeyedNum %= keyedNumbers.Count;
keyedNumbers[currentKeyedNum] = btnNum;
inputwindow.Text = "";
for(int i = 0; i < keyedNumbers.Count; i++)
inputwindow.Text += keyedNumbers[i].ToString();
}
private void button1_Click(object sender, EventArgs e)
{
pressButton(1);
}
private void button2_Click(object sender, EventArgs e)
{
pressButton(2);
}
private void button3_Click(object sender, EventArgs e)
{
pressButton(3);
}
private void button4_Click(object sender, EventArgs e)
{
pressButton(4);
}
private void button5_Click(object sender, EventArgs e)
{
pressButton(5);
}
private void button6_Click(object sender, EventArgs e)
{
pressButton(6);
}
private void button7_Click(object sender, EventArgs e)
{
pressButton(7);
}
private void button8_Click(object sender, EventArgs e)
{
pressButton(8);
}
private void button9_Click(object sender, EventArgs e)
{
pressButton(9);
}
private void clear_Click(object sender, EventArgs e)
{
currentKeyedNum = 0;
for(int i = 0; i < keyedNumbers.Count; i++)
keyedNumbers[i] = 0;
}
}
}
[/code]
also, you could probably get rid of all those buttonX_click events and boil it down to one method like so:
[code]
public Form1()
{
InitializeComponent();
for(int i = 0; i < 5; i++)
keyedNumbers.Add(0);
this.button1.Click += new System.EventHandler(this.pressButton);
this.button2.Click += new System.EventHandler(this.pressButton);
//etc
}
private void pressButton(object sender, EventArgs e)
{
int btnNum = Convert.ToInt32((sender as Button).Text);
currentKeyedNum++;
//loop around and start entering numbers at the first index again if they have entered 5 already
currentKeyedNum %= keyedNumbers.Count;
keyedNumbers[currentKeyedNum] = btnNum;
inputwindow.Text = "";
for(int i = 0; i < keyedNumbers.Count; i++)
inputwindow.Text += keyedNumbers[i].ToString();
}
[/code]
although that last bit is slightly hacky as it relies on casting the button text to an int, not really a great idea
[QUOTE=sim642;32059039]It's difficult to find the cause unless you show some code.[/QUOTE]
For some reason it works fine when I use a pointer to the class with the text but it breaks when dont use a pointer :iiam:
Has anyone here used JSonCpp?
Im trying to use it but I cant get it to parse corectly.
-snip-
Woops i missed putting a coma after each line
Anyone know if a top-down multiplayer game with 30+ simultaneous players would be possible with Love2D? Would it be smooth? Which language/framework would be most suitable for this project if one wants to get it done as fast as possible? XNA is certainly an alternative, but I'd prefer something else to get support on OS X and Linux.
Can someone explain the virtual keyword in C++?
I get that its basically allows you to override methods, but when you override a function does the base function still get called?
And why do you need to make the destructor of a class as virtual when inheriting from a different class?
[QUOTE=Richy19;32079537]Can someone explain the virtual keyword in C++?
I get that its basically allows you to override methods, but when you override a function does the base function still get called?
And why do you need to make the destructor of a class as virtual when inheriting from a different class?[/QUOTE]
The thing is, when you call an object's method in C++, what function to call is determined by what variable that object is stored in. If you store it or a pointer to it in the derived type, C++ will use the derived method. Though if you have a derived object in a variable of it's base type, C++ will call the base function. If it sees that the function is declared virtual, it checks to see if the object really is one of the subclasses, and if it is it uses the derived method instead. In some languages you don't even need to use the keyword virtual, but I think it's for performance reasons in C++, since runtime function lookup has a tad bigger overhead than compile time function lookup.
[QUOTE=thf;32079950]The thing is, when you call an object's method in C++, what function to call is determined by what variable that object is stored in. If you store it or a pointer to it in the derived type, C++ will use the derived method. Though if you have a derived object in a variable of it's base type, C++ will call the base function. If it sees that the function is declared virtual, it checks to see if the object really is one of the subclasses, and if it is it uses the derived method instead. In some languages you don't even need to use the keyword virtual, but I think it's for performance reasons in C++, since runtime function lookup has a tad bigger overhead than compile time function lookup.[/QUOTE]
so from what i understand it allows you to do:
class a
{
virtual something();
}
class b : public a
{
virtual something(); // does different stuff
}
class c : public a
{
virtual something(); // does different stuff
}
vector<a> list;
list.add(b);
list,add(c);
list[0].something(); // calls b something() because it is virtual
list[1].soomething(); // calls c something() because its virtual
Sorry, you need to Log In to post a reply to this thread.