• What do you need help with? V. 3.0
    4,884 replies, posted
Assuming no entry is longer than tabwidth, anyway
Just a quick question, where would I start if I wanted to learn networking using C# and XNA, say for example have a controller on a windows phone control an image on a desktop.
[QUOTE=Nigey Nige;33614728]You want: [cpp] number + "\t" + "|" + name + "\t" + "|" + result; [/cpp][/QUOTE] What exactly does "\t" do? Just for future reference Because I need to have the same amount of space even if the words are different lengths (so a 5 letter word would need, say, 5 spaces after and a 4 letter word would need 6) (Sorry if I was unclear)
[QUOTE=fylth;33614782]What exactly does "\t" do? Just for future reference Because I need to have the same amount of space even if the words are different lengths (so a 5 letter word would need, say, 5 spaces after and a 4 letter word would need 6)[/QUOTE] It's a tab character, like \n is a newline character. Possible uses include: 1 - Aligning text 2 - Being inferior/superior to 4 spaces 3 - Trolling WAYWO
That's almost what I need, still get these problems though: [IMG]http://i43.tinypic.com/sdhfv9.jpg[/IMG] (The first image has Subjects out of order, the second has one of the records out of order after a short Subject) That would probably suffice (we're not being marked a lot on presentation), but if anyone has further ideas I would appreciate them
Making my first program, lottery basically, and well something is wrong, lets say buying number costs 50 cent. I have 1.50 Euros. i want to buy 4 numbers, I try: it says not enough cash now if I try buying 3 or 2 it keeps saying not enough cash to buy those 4 numbers, it's like stuck in it or something. Please help. here is image: [IMG]http://i411.photobucket.com/albums/pp196/arleitiss/Untitled-23.png[/IMG] And here is piece of code: [code] int LineChoice = in.nextInt(); // Stores amount of lines user chose for later use in number pick. while (LineChoice <= 0 || LineChoice > 4) // Makes sure player doesn't enter line choice below or equal to 0 or more than 4. { System.out.println("Sorry but "+LineChoice+" is invalid amount of lines. Please try again."); // Tells user that amount he/she chose is invalid. LineChoice = in.nextInt(); // As it's loop, if error shows it re-asks number of lines. } if(LineChoice == 1) // Checks for users line choice. { PlayerCash -= 0.50; // If chose 1, then it will deduct 50 cent from PlayerCash. System.out.println("You've purchased 1 line, you have been charged 0.50 EUR, your balance is: "+PlayerCash+" EUR"); // Tells user how many lines he/she purchased and tells how much cash he has left. } else if(LineChoice == 2) // Checks for users line choice. { while(PlayerCash < 1.0) // Checks if user has enough cash to buy 2 lines, if under 1 euro then no. { // The reason linechoice 1 didn't have such thing is because if he has less than 50 cent game wont start at all. System.out.println("Sorry you don't have enough cash to buy 2 lines, try just one."); // Suggests user to try buying just 1 line. LineChoice = in.nextInt(); // As it's loop, if error shows it re-asks number of lines } PlayerCash -= 1; // Deducts 1 euro from players total cash. System.out.println("You've purchased 2 lines, you have been charged 1 EUR, your balance is: "+PlayerCash+" EUR"); // Tells user how many lines he/she purchased and tells how much cash he has left. } else if(LineChoice == 3) // Checks for users line choice. { while(PlayerCash < 1.50) // Checks if user has enough cash to buy 3 lines, if under 1.50 euros then no. { System.out.println("Sorry you don't have enough cash to buy 3 lines, try two or one."); // If not enough cash, it suggests buying just one or two lines. LineChoice = in.nextInt(); // As it's loop, if error shows it re-asks number of lines } PlayerCash -= 1.5; // Deducts 1.5 euros from players total cash. System.out.println("You've purchased 3 lines, you have been charged 1.50 EUR, your balance is: "+PlayerCash+" EUR"); // Tells user how many lines he/she purchased and tells how much cash he has left. } else if(LineChoice == 4) // Checks for users line choice. { while(PlayerCash < 2.0) // Checks if user has enough cash to buy 4 lines, if under 2 euros then no. { System.out.println("Sorry you don't have enough cash to buy 4 lines, try three, two or one."); // If not enough cash, it suggests buying just one, two or three lines. LineChoice = in.nextInt(); // As it's loop, if error shows it re-asks number of lines } PlayerCash -= 2; // Deducts 2 euros from players total cash. System.out.println("You've purchased 4 lines, you have been charged 2 EUR, your balance is: "+PlayerCash+" EUR"); // Tells user how many lines he/she purchased and tells how much cash he has left. }[/code] [editline]8th December 2011[/editline] oh fuck the comments...
Waaaay too many comments.
[QUOTE=ROBO_DONUT;33619707]Waaaay too many comments.[/QUOTE] Apparently my shite headded lecturer requires us to "comment a lot" so there i give her, nearly every line commented.
I remember seeing someone told to comment frequently, so after a line that prints to the console, he put "//prints to console" as the comment.
[QUOTE=arleitiss;33619423]One line costs .50 Cents.[/QUOTE] Half a cent? That's really cheap!
[QUOTE=Z_guy;33611193]How are you storing your Car instances?[/QUOTE] In a vector [editline]8th December 2011[/editline] [QUOTE=mechanarchy;33610594]I assume this is purely for testing, but you're supposed to create sf::Images once and then refer to them multiple times in sf::Sprites. If you keep re-creating your Image you'll keep reloading the file and bloat out your memory usage.[/QUOTE] There's just the one sprite and image for each colour car here. Also shouldn't the sf::Images be freed when Car is? [editline]8th December 2011[/editline] [QUOTE=Jookia;33610516]Are you sure the constructor is being called?[/QUOTE] yep [editline]8th December 2011[/editline] [QUOTE=Samuka97;33610482]Well, the sf::Image [b]is[/b] being loaded correctly, there's no doubt in that. I think that the problem is that the sf::Image is deleted before the sprite itself is drawn, causing it to have the same effect as the image not being loaded correctly. I'm having the same problem with my game. I can fix it by just sending the sf::Image everytime I'm gonna draw an entity, but that's not too efficient so I'm open to suggestions :v:[/QUOTE] The sf::Image lives in the same struct alongside the sf::Sprite so I don't think it would be getting deleted, but maybe there's some nasty C++ shit that's biting me here. [editline]8th December 2011[/editline] [QUOTE=Richy19;33610400]Because I found that on linux the images didnt show correctly unless you load them after the openGL context has been created.[/QUOTE] The sf::Images are constructed when MainMenuBackground::Car is constructed, which is when MainMenuBackground is constructed, which is when Game is constructed, which I think is [i]before[/i] the RenderWindow is either constructed or opened. So you may be on to something here. Thanks, I'll check this out tonight.
[QUOTE=swift and shift;33622832]There's just the one sprite and image for each colour car here. Also shouldn't the sf::Images be freed when Car is?[/QUOTE] You create an sf::Image resource which actually holds the image data. Usually you'd create it once and it would last the life of the program (or level, whenever you change assets). You then create multiple sf::Sprites that are unique to each entity instance and only last as long as that instance does. The Sprite refers to an existing sf::Image. Don't create multiple sf::Images, you'll just end up using heaps of memory very quickly when it's not necessary.
I have a teeny issue I get a NullReferenceExceptio at [code]using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; namespace GungeonCrawl { public class WeaponCarried { int spread; ContentManager Content; Texture2D BulletTexture, WeaponTexture; Bullet bullet; Game1 main = new Game1(); Vector2 muzzleposition, origin, ejectposition; string Weapon; public int Ammo; int maxammo, bulletpershot; float firespeed, firetimer, reloadtimer, rotation; Rectangle Weaponrectangle; public void Initialize(Vector2 Position, String Weapon) { if (Weapon == "Mac10") { WeaponMac10(); } } public void Update(bool fire, GameTime gametime, Vector2 position, float rotation) { Weaponrectangle = new Rectangle(WeaponTexture.Width, WeaponTexture.Height, (int)position.X, (int)position.Y); this.rotation = rotation; if (fire == true && firetimer <= 0 && Ammo > 0) { Ammo--; for (int i = 0; i < bulletpershot; i++) { Bullet bullet = new Bullet(); bullet.Initialize(muzzleposition, BulletTexture, spread); main.bulletlist.Add(bullet); } } else if (Ammo <= 0) { reloadtimer -= gametime.ElapsedGameTime.Milliseconds; } } public void Draw(SpriteBatch spriteBatch) { spriteBatch.Draw(WeaponTexture, Weaponrectangle, null, Color.White, rotation, origin, SpriteEffects.FlipVertically, 0); } public void WeaponMac10() { BulletTexture = main.SmallBulletTexture; WeaponTexture = main.Mac10Texture; [highlight]Weaponrectangle = new Rectangle(WeaponTexture.Width, WeaponTexture.Height, 0, 0);[/highlight] maxammo = 32; Ammo = 32; bulletpershot = 1; reloadtimer = 100f; muzzleposition = new Vector2(1, 3); origin = new Vector2(15, 3); } } } [/code] It says the texture is null despite grabbing it from [code]protected override void LoadContent() { characterbody = Content.Load<Texture2D>("Character_body"); debug = Content.Load<SpriteFont>("Debug"); pellet = Content.Load<Texture2D>("Pellet"); [highlight]SmallBulletTexture = Content.Load<Texture2D>("smallbullet"); Mac10Texture = Content.Load<Texture2D>("mac_10");[/highlight] defaultpointer = Content.Load<Texture2D>("DefaultPointer"); V = Content.Load<Texture2D>("Player_V"); spriteBatch = new SpriteBatch(GraphicsDevice); }[/code] In the Game1.cs (The textures are in a public Texture2D) I cannot come up with a clean way to do it, only other idea is to first send the texture to the Player.cs then to RightArm.cs and then finally to CarriedWeapon.cs but that would be very very messy because I would have to send ever weapon texture at once and it would be an unneccesary amount of code for something so simple.
[QUOTE=arleitiss;33619889]Apparently my shite headded lecturer requires us to "comment a lot" so there i give her, nearly every line commented.[/QUOTE] By comment a lot I bet she means comments that make sense. Commenting about what your System.out.println() does is pointless as all the reader has to do is look at the string.
[QUOTE=Red scout?;33626041]I have a teeny issue I get a NullReferenceExceptio at [code]...[/code] In the Game1.cs (The textures are in a public Texture2D) I cannot come up with a clean way to do it, only other idea is to first send the texture to the Player.cs then to RightArm.cs and then finally to CarriedWeapon.cs but that would be very very messy because I would have to send ever weapon texture at once and it would be an unneccesary amount of code for something so simple.[/QUOTE] Looking through a tutorial on Xna I ran through, this kind of prblem showed with a random number generator object. the code had in Game1.cs: [code]public class Game1 : Microsoft.Xna.Framework.Game { ... public Random rnd { get; private set; } ... } public Game1() { ... rnd = new Random(); ... }[/code] It was accessed by classes of a game component thusly: [code]public class SpriteManager : Microsoft.Xna.Framework.DrawableGameComponent { ... protected override void LoadContent() { ... private void ResetSpawnTime() { nextSpawnTime = ((Game1)Game).rnd.Next( ... }[/code] Not sure if that'll help. As a side note, this code (running as a GameComponent) overrides LoadContent. Then all images it is loading are local to the class, and the LoadContent Method calls base.LoadContent(); at the end to call the Game1.cs Method. May be something else to look into. I don't remember much about Xna so sorry I can't help further. I didn't stick with it.
[QUOTE=subenji99;33626590]Looking through a tutorial on Xna I ran through, this kind of prblem showed with a random number generator object. the code had in Game1.cs: [code]public class Game1 : Microsoft.Xna.Framework.Game { ... public Random rnd { get; private set; } ... } public Game1() { ... rnd = new Random(); ... }[/code] It was accessed by classes of a game component thusly: [code]public class SpriteManager : Microsoft.Xna.Framework.DrawableGameComponent { ... protected override void LoadContent() { ... private void ResetSpawnTime() { nextSpawnTime = ((Game1)Game).rnd.Next( ... }[/code] Not sure if that'll help. As a side note, this code (running as a GameComponent) overrides LoadContent. Then all images it is loading are local to the class, and the LoadContent Method calls base.LoadContent(); at the end to call the Game1.cs Method. May be something else to look into. I don't remember much about Xna so sorry I can't help further. I didn't stick with it.[/QUOTE] Well, the issue is the texture being null.
C#, Getting values between classes, and setting them. Yes google exists but all the tutorials are not good for retards, I know the methods n get(blabla); and whatever but could someone just explain it over detailed
[QUOTE=DestWa;33628860]C#, Getting values between classes, and setting them. Yes google exists but all the tutorials are not good for retards, I know the methods n get(blabla); and whatever but could someone just explain it over detailed[/QUOTE] What do you mean? Seems like you already know. Classes holds methods and information. You can create objects from the classes. Let's say you have a class called Item. Then you can make it hold whatever information you may like, examples may be name, description or weight. You can write methods that retrieves that information, sends it away to other objects and so on. From a beginner to a beginner :v: I hope I'm right.
[QUOTE=swift and shift;33622832]In a vector [editline]8th December 2011[/editline] There's just the one sprite and image for each colour car here. Also shouldn't the sf::Images be freed when Car is? [editline]8th December 2011[/editline] yep [editline]8th December 2011[/editline] The sf::Image lives in the same struct alongside the sf::Sprite so I don't think it would be getting deleted, but maybe there's some nasty C++ shit that's biting me here. [editline]8th December 2011[/editline] The sf::Images are constructed when MainMenuBackground::Car is constructed, which is when MainMenuBackground is constructed, which is when Game is constructed, which I think is [i]before[/i] the RenderWindow is either constructed or opened. So you may be on to something here. Thanks, I'll check this out tonight.[/QUOTE] I may be a little late here but I think it has something to do with the way sf::Images and sf::Sprites are related. From what I remember, sf::Sprite doesn't store the sf::Image itself but stores a reference to the image, so if you destroy the instance of the sf::Image you initialized the sprite with it doesn't have an image anymore. I battled the same problem a while back, don't remember how I solved it though.
So I'm kinda stuck in a confused position. I still can't figure anything out with a confusing method, and the programs I've done are pretty easy for the most part. Anyone have any programs ideas that I could make in Java? Not too simple but challenging, that kind of thing. I tried learning slick2D but even when I imported the jar files and set the native library I kept on getting some weird error about the jar files not being imported, so I gave up.
[QUOTE=Blueridge;33635702]So I'm kinda stuck in a confused position. I still can't figure anything out with a confusing method, and the programs I've done are pretty easy for the most part. Anyone have any programs ideas that I could make in Java? Not too simple but challenging, that kind of thing. I tried learning slick2D but even when I imported the jar files and set the native library I kept on getting some weird error about the jar files not being imported, so I gave up.[/QUOTE] What IDE are you using?
Can anyone recommend a book on XNA that REALLY goes into depth on how everything works? I can't learn very well unless I know everything that's going on.
I'm using the LOVE framework. How can I get a sounds output level?
-Snip- I got some help from my teacher and figured out the solution. Here's my code. The program takes two inputs in 24-hour format (e.g 2230, 0415) with the second one being later. It then finds the difference. [code]#Lab 5 Part 4 #09/12/2011 import utils time1 = utils.get_int("Please enter a time in 24-hour format (####): ") time2 = utils.get_int("Please enter a second time in 24-hour format (####): ") #We are lazy so we use Deryk's convenient utility to grab our inputs. hours1 = time1 / 100 ##e.g: 2230 / 100 = 22 hours2 = time2 / 100 ##e.g: 0415 #Separate hours to break this question down. minutes1 = time1%100 ##e.g 2230 %100 = 30 minutes2 = time2%100 #Same for minutes hours = hours2 - hours1 + 24 if hours > 24: hours -= 24 #If we go over a day, we can just convert 24 hours into a day. We don't need to calculate the days (Example: 2230 on Tuesday and 0415 on Wednesday) minutes = minutes2 - minutes1 if minutes < 0: minutes += 60 hours -= 1 #In calculating the minutes, we may get negative. So we borrow an hour. print 'The difference was', hours, 'hours and', minutes, 'minutes.' [/code]
-snip-
I'm working on a program that fetches definitions and the like from the Dictionary.com API. The API returns XML files like these : [URL="http://naarkie.shellmix.com/files/idiotdefine.xml"]definition for 'idiot'[/URL] You'll notice that all the content is inside CDATA tags, which my XML parser ignores. How can I get around this? The XML parser uses XPath to parse data. For example, "//def[@charcnt*]" should return "very stupid person" or just "<![CDATA[ very stupid person ]]>", but the parser ignores anything inside CDATA tags. What should I do?
I get a NullReferenceException on line 152, I have no idea why it does this. Bleh, I hate being bad at stuff. [cpp]using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; namespace GungeonCrawl { /// <summary> /// This is the main type for your game /// </summary> public class Game1 : Microsoft.Xna.Framework.Game { WeaponCarried weaponcarried; List<WeaponCarried> weaponcarriedlist; public string mousedebug1, mousedebug2; public SpriteFont debug; Bullet bullet; List<Bullet> bulletlist; public Vector2 MousePosition; Player player = new Player(); Pointer mouse = new Pointer(); KeyboardState keyboardstate; int money; bool playerspawned; GraphicsDeviceManager graphics; SpriteBatch spriteBatch; public Texture2D V, defaultpointer, pellet, SmallBulletTexture; public Texture2D characterbody, characterlegs; public Texture2D Mac10Texture; //weapontextures public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } /// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { base.Initialize(); weaponcarriedlist = new List<WeaponCarried>(); bulletlist = new List<Bullet>(); mouse.Initialize(defaultpointer); player.Initialize(characterbody, characterlegs, pellet, this); playerspawned = true; bullet = new Bullet(); } /// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { characterlegs = Content.Load<Texture2D>("Leg_sheet"); characterbody = Content.Load<Texture2D>("Character_body"); debug = Content.Load<SpriteFont>("Debug"); pellet = Content.Load<Texture2D>("Pellet"); SmallBulletTexture = Content.Load<Texture2D>("smallbullet"); Mac10Texture = Content.Load<Texture2D>("mac_10"); defaultpointer = Content.Load<Texture2D>("DefaultPointer"); V = Content.Load<Texture2D>("Player_V"); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here } /// <summary> /// UnloadContent will be called once per game and is the place to unload /// all content. /// </summary> protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } /// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { foreach (WeaponCarried weaponcarried in weaponcarriedlist) { weaponcarried.Update(player.fire, gameTime, player.Position, player.rotation); } if (player.pickup == "Mac10") { WeaponCarried weaponcarried = new WeaponCarried(); weaponcarried.Initialize(player.Position, player.pickup, Mac10Texture, SmallBulletTexture); weaponcarriedlist.Add(weaponcarried); player.pickup = ""; } MousePosition.X = mouse.mouse.X; MousePosition.Y = mouse.mouse.Y; foreach(Bullet bullet in bulletlist) { bullet.Update(); } if (playerspawned == true) { player.Update(gameTime); } mouse.Update(); // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); keyboardstate = Keyboard.GetState(); // TODO: Add your update logic here mousedebug1 = Convert.ToString(mouse.mouse.X); mousedebug2 = Convert.ToString(mouse.mouse.Y); base.Update(gameTime); } /// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); foreach (Bullet bullet in bulletlist) { bullet.Draw(spriteBatch); } foreach (WeaponCarried weaponcarried in weaponcarriedlist) { weaponcarried.Draw(spriteBatch); } player.Draw(spriteBatch); mouse.Draw(spriteBatch); spriteBatch.End(); base.Draw(gameTime); } public void ShootWeapon() { Bullet bullet = new Bullet(); bullet.Initialize(weaponcarried.muzzleposition, weaponcarried.BulletTexture, weaponcarried.spread); bulletlist.Add(bullet); } } } [/cpp]
-SNIP- Maybe its just me misreading this, but where is Weaponcarried actually assigned to anything ?
[QUOTE=meeces2911;33638624]-SNIP- Maybe its just me misreading this, but where is Weaponcarried actually assigned to anything ?[/QUOTE] I rewrote it. In public class Game1 WeaponCarried weaponcarried; Bullet bullet; in Initialize() weaponcarried = new WeaponCarried(); bullet = new Bullet(); I have no idea why it still refuses to work
What's a good, well-explained guide to XNA?
Sorry, you need to Log In to post a reply to this thread.