• What do you need help with? V. 3.0
    4,884 replies, posted
what's path? [editline]24th December 2011[/editline] and what do you mean 'in cpp or whatever'? [editline]24th December 2011[/editline] I presume you mean in the header file itself, so I put it there. Now, when I call [cpp] Spaceship ship1("Ship one", 2000, 1000, 86400); ship1.LoadImage("movingobject.png"); [/cpp] It says 'class Spaceship' has no member named 'LoadImageA'|
[QUOTE=Meatpuppet;33878859]what's path? [editline]24th December 2011[/editline] and what do you mean 'in cpp or whatever'?[/QUOTE] Path is the name of the string that's passed in as the filename, like "c:/test/ship.png". Normally in C++ projects, you split everything up into .h and .cpp files. The .h (or 'header') files do all the class declarations and function prototypes and stuff, then the .cpp files include the headers but flesh them out and contain actual definitions, like full function bodies. [url=http://en.wikipedia.org/wiki/Header_file]This page[/url] explains it better. [editline]24th December 2011[/editline] the loadimage thing is probably because there's a function called LoadImage already, try renaming it to loadShipImage or something (and make sure the name is the same everywhere you use it - the header declaration, cpp definition and cpp usage, where you actually call it)
i've been doing it wrong the whole time [editline]24th December 2011[/editline] oh GOD [editline]24th December 2011[/editline] So what do I do to put the functions in a separate file? [editline]24th December 2011[/editline] In private: [cpp]class Spaceship { private: unsigned int Mass; unsigned int Fuel_Level; unsigned int Life_Support_Time; std::string imageName; sf::Image myImage; sf::Sprite shipimage; char Name[20];[/cpp] The function: [cpp]int Spaceship::ShipLoadImage(const std::string& path) { imageName = path; int code = myImage.LoadFromFile(imageName); shipimage = sf::Sprite(myImage); return code; }[/cpp] But when I [cpp] shipimage.SetPosition(x,y);[/cpp] In main It says 'shipimage' was not declared in this scope|
like this: ship.h: [code] #ifndef SHIP_H #define SHIP_H class Spaceship { private: std::string imageName; sf::Image myImage; sf::Sprite mySprite; public: int setShipImage(const std::string& path); }; #endif [/code] ship.cpp: [code] #include "ship.h" int Spaceship::setShipImage(const std::string& path) { imageName = path; int code = myImage.LoadFromFile(imageName)); mySprite = sf::Sprite(myImage); return code; } [/code] then you should have a main file where your SFML loop and everything is done: [code] #include "ship.h" ...... Spaceship ship1; ship1.setShipImage("c:/test/lol.png"); ...... //then draw it in the loop or whatever, you'll probably need a function in Spaceship to get its sprite [/code]
Is there a way to use windows forms instead of the ugly Java ones?
I made [cpp]sf::Sprite GetShipImage() { return shipimage; }[/cpp] In the header file. The function is good, but in the main file [cpp] GetShipImage().SetPosition(x,y);[/cpp] Makes it say: 'GetShipImage' was not declared in this scope
[QUOTE=toaster468;33879216]Is there a way to use windows forms instead of the ugly Java ones?[/QUOTE] Like [url=http://today.java.net/pub/a/today/2003/12/08/swing.html]this?[/url] [code] try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (UnsupportedLookAndFeelException ex) { System.out.println("Unable to load native look and feel"); } [/code] [editline]24th December 2011[/editline] [QUOTE=Meatpuppet;33879305]Makes it say: 'GetShipImage' was not declared in this scope[/QUOTE] You have to do it as a function of the ship you made, like (assuming the ship you made is called ship1): ship1.GetShipImage().SetPosition(x,y);
[QUOTE=Lord Ned;33878857]I thought commonly accepted for input was to capture WM_KEYDOWN/KEYUP for movement, and WM_CHAR for typing? Could just keep people from binding movement keys to silly stuff like {], but it's theoretically fixeable with if statements, though how well that'll hold up long term is questioanble.[/QUOTE] Yeah. Maybe I have misunderstood your intention, and why you need them to be lower case. It seemed to me like you were expecting an ascii character from WM_KEY*. Maybe i'm wrong. You are right though. You should use WM_KEY* for the literal key, and WM_CHAR for the character entered.
[QUOTE=Philly c;33879606]Yeah. Maybe I have misunderstood your intention, and why you need them to be lower case. It seemed to me like you were expecting an ascii character from WM_KEY*. Maybe i'm wrong. You are right though. You should use WM_KEY* for the literal key, and WM_CHAR for the character entered.[/QUOTE] I was hoping to get the ascii-key from WM_KEYDOWN/wParam, because all of my input rebinding works off of ints (atoi, etc.) - it's adaptable in the code, but when reading a config file it was having trouble because "w" was different than "W", so it wasn't looking in the right spot. That's fixable in theory. What I'm instead stuck trying to debug now is my keypress events firing for a lot longer after the key is released (0.5-3.0s). On my KeyUp, I have a printf to print. If I release the the key, the messages continue to fire long after my keyboard key is up and long after everything else. Is it something to do with my way of getting messages? [cpp] int MainApp::RunMainLoop() MSG msg = {0}; m_fastTimer.Reset(); while(msg.message != WM_QUIT) { //If there are windows messages (keypresses, mousemove, etc), process them. if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { //Do game stuff! //UpdateScene() //Render()->DrawScene() } //WM_KEYDOWN sends as "A" even if capslock/shift is off. if(msg.message == WM_KEYDOWN) { //To fix this, we can use tolower. //However, this still has issues with keys like [, though it's not //tolower's fault. Key_Event( tolower(msg.wParam), true); } else if (msg.message == WM_KEYUP) { printf("Key %d Up!\n", msg.wParam); Key_Event( tolower(msg.wParam), false); } } return (int)msg.wParam; } [/cpp] Prints: 400-500 "Key: 87 Up!" from one key release. My guess is my peekmessage/if msg = WM_KEYUP is wrong, and I don't know the message system well enough to say what.
The WPARAM for WM_KEY is a [url=http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx]virtual key code[/url]. Not ascii because it would be impossible to represent keys other than character keys. That's why it's irrelevant whether it's upper or lower case because it refers to a key. Also it's just a quirk that A-Z have no defines and are their ascii equivalent. You should separate a key event from a text/character event, and sort out your binds a different way.
[QUOTE=Meatpuppet;33879305]I made [cpp]sf::Sprite GetShipImage() { return shipimage; }[/cpp] In the header file. The function is good, but in the main file [cpp] GetShipImage().SetPosition(x,y);[/cpp] Makes it say: 'GetShipImage' was not declared in this scope[/QUOTE] Use this: [cpp]sf::Sprite & GetShipImage() { return shipimage; }[/cpp] instead of this: [cpp]sf::Sprite GetShipImage() { return shipimage; }[/cpp] The & means that shipimage will be returned as a reference. Doing so can increase performance significantly, since it won't copy and send all the data in the Sprite. You will be able to access the data of shipimage directly, instead of a temporary copy of it.
hey so i'm trying to use spriteBatches and quads in love2d and this is what i have so far... [code] World = Class{function(self) self.image = love.graphics.newImage('spritebatches/default/default.png') self.image:setFilter('nearest', 'linear') self.tileQuads = {} for x=1, 16 do self.tileQuads[x] = {} for y=1, 13 do self.tileQuads[x][y] = love.graphics.newQuad( x*16, y*16, 16, 16, self.image:getWidth(), self.image:getHeight()) end end self.tileIds = {} i = 0 for sx=1, 32 do for sy=1, 26 do i = i + 1 self.tileIds[i] = { x=sx, y=sy } end end self.grid = {} for x=1, 32 do self.grid[x]= {} for y=1, 26 do self.grid[x][y] = 60 end end self.batch = love.graphics.newSpriteBatch( self.image, 832 ) end} function World:batchUpdate() for x=1, 16 do for y=1, 13 do -- if its 0 then add that id corrosponding to the spriteSheet local sx,sy = self.tileIds[self.grid[x][y]].x, self.tileIds[self.grid[x][y]].y local quad = self.tileQuads[sx][sy] self.batch:addq(quad, x*16, y*16) end end end function World:Draw() love.graphics.setColor( 255, 255, 255 ) love.graphics.draw(self.batch) end [/code] It works but i have no idea whether it can be simplified at all, can anyone see anyway it can be improved?
[QUOTE=Philly c;33879997]The WPARAM for WM_KEY is a [url=http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx]virtual key code[/url]. Not ascii because it would be impossible to represent keys other than character keys. That's why it's irrelevant whether it's upper or lower case because it refers to a key. Also it's just a quirk that A-Z have no defines and are their ascii equivalent. You should separate a key event from a text/character event, and sort out your binds a different way.[/QUOTE] Acknowledged. Here's how my binds work: [cpp] char *keyBindings[256]; void OnKeyPress(int keyCode) { if(keyBindings[keycode]) //Creates an event with the char* in keybindings, eg; +forward } void LoadConfig() { //open file, read ascii-char + command bound ot //keyBinding[ascii-char] = command; } [/cpp] I'll have to come up with a different method (or just convert the ascii-char to all-caps), but I don't think that's a good idea. Is there a way to map ASCII chars to virtual key-codes, so I could store them in the array at their virtual-keycode position, which would then theoretically match the input? I still need to get the KEY_UP to stop firing for 3 seconds after the key release. It's messing up my stuff because it fires once (code works fine) and then 400 more times and the code goes "uh why are you releasing a key that hasn't been pressed".
When I run my java programs through the console it runs an older version even from the same file that Eclipse runs my program, and eclipse isn't effected by this problem, any help?
[QUOTE=ief014;33880248]Use this: [cpp]sf::Sprite & GetShipImage() { return shipimage; }[/cpp] instead of this: [cpp]sf::Sprite GetShipImage() { return shipimage; }[/cpp] The & means that shipimage will be returned as a reference. Doing so can increase performance significantly, since it won't copy and send all the data in the Sprite. You will be able to access the data of shipimage directly, instead of a temporary copy of it.[/QUOTE] Same error: 'GetShipImage' was not declared in this scope|
[QUOTE=Meatpuppet;33881928]Same error: 'GetShipImage' was not declared in this scope|[/QUOTE] Show us the code :D
Spaceship.h: [url]http://pastebin.com/5h4nnMaX[/url] Spaceship.cpp: [url]http://pastebin.com/C2htPb4B[/url] Main.cpp: [url]http://pastebin.com/kicMJK8u[/url] [editline]24th December 2011[/editline] warning: horrible code
You have to reference a ship when calling that function, at the moment it doesn't know which ship you're talking about. [code] ship1.GetShipImage().SetPosition(x,y); ... App.Draw(ship1.GetShipImage()); [/code]
Thanks dude, I don't know why I didn't think of that. Now it's giving me [cpp] ship1.ShipLoadImage("movingobject.png");[/cpp] Undefined reference to Spaceship::ShipLoadImage(std::string constant&)
Hm, that's a weird one. Try adding #include <string> next to #include <string.h>, just to test.
I presume you mean <cstring>, hold on [editline]24th December 2011[/editline] Nope. Odd. Hasn't happened before
Nah, I meant string...I don't know much about C (or C++ to be honest :p) but I think you're using a lot of C stuff in a C++ app and you shouldn't be. AFAIK, <cstring> is the C version and <string> is C++, which lets you use std::strings.
Nope, still nothing... Also, I'm not. I don't know a lick of C.
[QUOTE=Meatpuppet;33883569]Nope, still nothing... Also, I'm not. I don't know a lick of C.[/QUOTE] C is essentially C++ without classes or such a large standard library. IIRC <cstring> only includes methods that deal with char[]s, like strlen, strcomp, etc. and string.h includes std::String as well as similar methods that work with std::String.
[QUOTE=robmaister12;33883872]C is essentially C++ without classes or such a large standard library.[/QUOTE] And without templates, without function overriding, with less strict casting rules...
I want to reverse-engineer Ventrilo but I don't know Assembly, does anybody know a good resource to learn it from? Personally I'd like a video, but text or books are good too. I know C++ if that helps at all.
[QUOTE=Bumrang;33884218]I want to reverse-engineer Ventrilo but I don't know Assembly, does anybody know a good resource to learn it from? Personally I'd like a video, but text or books are good too. I know C++ if that helps at all.[/QUOTE] Instead of trying to reverse-engineer, you can just take a look at Mumble: [url]http://mumble.sourceforge.net/[/url] It does it's own audio stuff, but it can still connect to Ventrilo servers.
[QUOTE=Bumrang;33884218]I want to reverse-engineer Ventrilo but I don't know Assembly, does anybody know a good resource to learn it from? Personally I'd like a video, but text or books are good too. I know C++ if that helps at all.[/QUOTE] [url=http://www.mangler.org/]Mangler[/url]
I got it the other way around, Mumble is the server, Mangler is the client that can connect to Ventrilo 3.x servers: [url]http://www.mangler.org/[/url] [editline]24th December 2011[/editline] automerge ninja'd. This is a first.
I'd rather not run Linux in a VM just to connect to a vent server, so I can't use Mangler. Is there any way I can make my own program that connects to vent servers? If not, I will have to resort to reverse-engineering. I've actually wanted to learn assembly/reverse-engineering for quite a bit now and it will probably become [I]really[/I] useful in the future.
Sorry, you need to Log In to post a reply to this thread.