• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=JohanGS;39449165]How do I set these picture to be the background of the application (when I click a button)? [IMG]http://f2.braxupload.se/eyc4ck.bf1a9abbd0.png[/IMG] [editline]2nd February 2013[/editline] (C# by the way)[/QUOTE] You should be able to load them up by doing: [cpp]Image background1 = Image.FromFile("Bilder/bakgrund1.png"); // And so on[/cpp] And then to set them as your form background: [cpp]this.BackgroundImage = background1;[/cpp]
[QUOTE=RandomDexter;39448987]The instruction didn't really specify, but i think so... Always the space between the doubles and only one decimal. I hope it isn't to complicated[/QUOTE] Could you post the instructions perhaps? First year in college I had a similar task as homework, but we were supposed to take each number as separate input, not in one whole String.
[QUOTE=mobrockers2;39449164]But you don't know how many numbers your input will be (I assume this is what you mean by randomly long sequence)? Then when does your program stop taking input, and start doing the math? For example, you could request how many numbers the user will put in, before the user is asked to input the numbers themselves, this way you can stop asking for input when you reach the amount the user has said he would put in.[/QUOTE] yes, i meant randomly, sorry Gulen. let's say the limit is 5 numbers, how would i stick this in an array
If you're getting the numbers one by one, you could use a List. [cpp]List<double> numbers; numbers.add(Double.parseDouble("5.4")); numbers.get(2); // returns the third value you added, like a normal Array [/cpp]
[QUOTE=RandomDexter;39449280]yes, i meant randomly, sorry Gulen. let's say the limit is 5 numbers, how would i stick this in an array[/QUOTE] [cpp] Double numbers[]; Scanner s = new Scanner(System.in); for(int i = 0; i < 5; i++) { numbers[i] = s.nextDouble(); } [/cpp] pardon any mistakes
[QUOTE=Chris220;39449240]You should be able to load them up by doing: [cpp]Image background1 = Image.FromFile("Bilder/bakgrund1.png"); // And so on[/cpp] And then to set them as your form background: [cpp]this.BackgroundImage = background1;[/cpp][/QUOTE] The file location you wrote didn't work so I tried the one in the file properties, but if I do that, it won't be able to run on other computers. How do I prevent this?
Use the relative path from the .exe to the image, I guess? Unless you're already doing that?
[QUOTE=Gulen;39449350]If you're getting the numbers one by one, you could use a List. [cpp]List<double> numbers; numbers.add(Double.parseDouble("5.4")); numbers.get(2); // returns the third value you added, like a normal Array [/cpp][/QUOTE] to complicated for me, what about this? [code] Double[] array=new Double[6]; for(int i=0;i<array.length;i++){ array[i]=scan.nextDouble(); }[/code] Would it work :)
Yeah, but if you know that you'll only get 5 numbers, there's no need to have that sixth position there, just do a new Double[5] instead.
[QUOTE=RandomDexter;39449422]to complicated for me, what about this? [code] Double[] array=new Double[6]; for(int i=0;i<array.length;i++){ array[i]=scan.nextDouble(); }[/code] Would it work :)[/QUOTE] [cpp] Scanner s = new Scanner(System.in); Double numbers[]; System.out.println("How many numbers would you like to insert?"); int total = s.nextInt(); numbers = new Double[total]; for(int i = 0; i < total; i++) { System.out.println("Please insert the next number"); numbers[i] = s.nextDouble(); } [/cpp] Since you don't know how many numbers you're going to put in the array, this is what you'll want to do.
[QUOTE]Yeah, but if you know that you'll only get 5 numbers, there's no need to have that sixth position there, just do a new Double[5] instead. [/QUOTE] [QUOTE=mobrockers2;39449513][cpp] Scanner s = new Scanner(System.in); Double numbers[]; System.out.println("How many numbers would you like to insert?"); int total = s.nextInt(); numbers = new Double[total]; for(int i = 0; i < total; i++) { System.out.println("Please insert the next number"); numbers[i] = s.nextDouble(); } [/cpp] Since you don't know how many numbers you're going to put in the array, this is what you'll want to do.[/QUOTE] Thanks guys :)
[QUOTE=RandomDexter;39449535]Thanks guys :)[/QUOTE] Please use spaces and white lines in your code to improve readability :v:
[QUOTE=JohanGS;39449394]The file location you wrote didn't work so I tried the one in the file properties, but if I do that, it won't be able to run on other computers. How do I prevent this?[/QUOTE] This: [QUOTE=Gulen;39449416]Use the relative path from the .exe to the image, I guess? Unless you're already doing that?[/QUOTE] In my code, I was assuming that the 'Bilder' folder was in the same directory as the executable file. You may have to adjust your path if that's now how you have it set up!
How do I do that then?
If you have a project folder, with a Bin folder (in which your .exe is) and a Bilder folder (in which your images are), just move the Bilder folder into the Bin folder (or, if you plan on keeping the Bin folder, but have the Bilder next to it, change the string to "../Bilder/background1.png")
But I want it to work without having to send the project folder, what do?
[QUOTE=JohanGS;39449940]But I want it to work without having to send the project folder, what do?[/QUOTE] If you're going to have an image in your program, you're probably gonna need to send it in some form. So determine a directory structure that you like and would be easy for others to use, and just go with it.
Yeah, the project folder was just to fix it showing up while you're working on it. When you go to release your application, you're gonna have to send them the image as well.
[QUOTE=mobrockers2;39449545]Please use spaces and white lines in your code to improve readability :v:[/QUOTE] How do i do that :rolleyes:
[cpp]#ifndef MENUSTATE_H #define MENUSTATE_H #include "gamestate.h" class MenuState : public GameState { public: void Init(); void CleanUp(); void Pause(); void Resume(); void HandleEvents( StateManager *game ); void Update( StateManager *game ); void Draw( StateManager *game ); static MenuState* Instance() { return &_menuState; } protected: MenuState() { } private: static MenuState _menuState; }; #endif // MENUSTATE_H[/cpp] How would this make an undefined reference to MenuState::_menuState in MenuState::Instance?
[QUOTE=Asgard;39450719]#ifndef MENUSTATE_H #define MENUSTATE_H #include "gamestate.h" class MenuState : public GameState { public: void Init(); void CleanUp(); void Pause(); void Resume(); void HandleEvents( StateManager *game ); void Update( StateManager *game ); void Draw( StateManager *game ); static MenuState* Instance() { return &_menuState; } protected: MenuState() { } private: static MenuState _menuState; }; #endif // MENUSTATE_H How would this make an undefined reference to MenuState::_menuState in MenuState::Instance?[/QUOTE] Declare it before you make the method that returns it.
[QUOTE=account;39450747]Declare it before you make the method that returns it.[/QUOTE] Tried that before, doesn't matter.
[QUOTE=Gulen;39450547]Yeah, the project folder was just to fix it showing up while you're working on it. When you go to release your application, you're gonna have to send them the image as well.[/QUOTE] Sorry for being a bitch, but how do you do that? (I want to have the images in the .exe).
[QUOTE=JohanGS;39450792]Sorry for being a bitch, but how do you do that? (I want to have the images in the .exe).[/QUOTE] You can embed any file in the assembly by selecting the file in the Solution Explorer, and setting the content type to Embedded Resource. In code, you can retrieve a Stream using [url=http://msdn.microsoft.com/en-us/library/xc4235zt.aspx]Assembly.GetManifestResourceStream[/url]. I'll write up a sample program if you want to, just let me know.
Ok this should be a little clearer: I keep getting errors that Menu is not a class or namespace name and that Text is not a class or namespace name, which I have no idea why that's happening. Menu.h: [cpp]#ifndef TE_MMENU #define TE_MMENU #include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include <Source/Text/Text.h> #include <list> class Menu { public: static enum MenuResult { Exit, Options, Back, ChangeResolution, Play, Nothing }; MenuResult showMMenu(sf::RenderWindow &window); MenuResult showOMenu(sf::RenderWindow &window); MenuResult highlightButton(MenuResult menuresult); private: MenuResult getMenuResponse(sf::RenderWindow &window); MenuResult handleClick(int x, int y); Menu::MenuResult Menu::handleButtonHover(sf::RenderWindow &window, int x, int y); std::list<Text::MenuItem> menuItems; }; #endif [/cpp] Text.h: [cpp]#ifndef TE_TEXT #define TE_TEXT #include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include <Source/Menu/MainMenu.h> enum style { bold, italic, underlined }; class Text { ... struct MenuItem { public: sf::FloatRect buttonrect; static void highlightRectOutline(sf::RenderWindow &window, sf::Color color); Menu::MenuResult action; // here is the offending line }; ... } [cpp] [editline]2nd February 2013[/editline] Ok this should be a little clearer: I keep getting errors that Menu is not a class or namespace name and that Text is not a class or namespace name, which I have no idea why that's happening. Menu.h: [cpp]#ifndef TE_MMENU #define TE_MMENU #include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include <Source/Text/Text.h> #include <list> class Menu { public: static enum MenuResult { Exit, Options, Back, ChangeResolution, Play, Nothing }; MenuResult showMMenu(sf::RenderWindow &window); MenuResult showOMenu(sf::RenderWindow &window); MenuResult highlightButton(MenuResult menuresult); private: MenuResult getMenuResponse(sf::RenderWindow &window); MenuResult handleClick(int x, int y); Menu::MenuResult Menu::handleButtonHover(sf::RenderWindow &window, int x, int y); std::list<Text::MenuItem> menuItems; }; #endif [/cpp] Text.h: [cpp]#ifndef TE_TEXT #define TE_TEXT #include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include <Source/Menu/MainMenu.h> enum style { bold, italic, underlined }; class Text { ... struct MenuItem { public: sf::FloatRect buttonrect; static void highlightRectOutline(sf::RenderWindow &window, sf::Color color); Menu::MenuResult action; // here is the offending line }; ... } [/cpp]
[QUOTE=Meatpuppet;39451552] Text.h: [cpp]#ifndef TE_TEXT #define TE_TEXT #include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include <Source/Menu/MainMenu.h> enum style { bold, italic, underlined }; class Text { ... struct MenuItem { public: sf::FloatRect buttonrect; static void highlightRectOutline(sf::RenderWindow &window, sf::Color color); Menu::MenuResult action; // here is the offending line }; ... } [/cpp][/QUOTE] Could it have to do with the missing ending ; on that class?
That's not there in the actual code, I just typed that in on the post.
[QUOTE=horsedrowner;39450848]You can embed any file in the assembly by selecting the file in the Solution Explorer, and setting the content type to Embedded Resource. In code, you can retrieve a Stream using [URL="http://msdn.microsoft.com/en-us/library/xc4235zt.aspx"]Assembly.GetManifestResourceStream[/URL]. I'll write up a sample program if you want to, just let me know.[/QUOTE] Wouldn't that be horrible for a video game? Seems like the best way would be for him to learn what a path actually means.
[QUOTE=RandomDexter;39450636]How do i do that :rolleyes:[/QUOTE] [cpp] Double[] array = new Double[6]; for(int i = 0; i< array.length; i++) { array[i] = scan.nextDouble(); } [/cpp] Also it's best to use descriptive names for your variables. Though it isn't a big deal in such small program, it's generally not a good idea to call your Array 'array' and so on since you're bound to use more than one of a type at some point, and it's best to do it right from the beginning. [editline]3rd February 2013[/editline] God damnit facepunch's editor is pissing me off so much right now, had to edit my post like 20 times because editing fucks up cpp tags in some strange way..
[url]https://gist.github.com/97ace9631273fd37646d[/url] Anyone know what's wrong?
Sorry, you need to Log In to post a reply to this thread.