• What do you need help with? V. 3.0
    4,884 replies, posted
Got it. [cpp] sf::Event Event; while (App.GetEvent(Event)) { switch(Event.Type) { case sf::Event::Closed : App.Close(); case sf::Event::KeyPressed : if (Event.Key.Code == sf::Key::Escape) App.Close(); else if (Event.Key.Code == sf::Key::D) velocityX += .25; else if (Event.Key.Code == sf::Key::A) velocityX -= .25; else if (Event.Key.Code == sf::Key::W) velocityY += .25; else if (Event.Key.Code == sf::Key::S) velocityY -= .25; break; }[/cpp] This works, thanks. Can I nest multiple if's within those, so it will accept combos? Won't that be messy code, for every combination?
In OpenGL, should I be able to call glBegin() and then glEnd() immediately after with no errors? Here's what I'm doing: [csharp]ErrorCheck( "begin 1" ); GL.Begin( BeginMode.Quads ); GL.End(); ErrorCheck( "begin 2" );[/csharp] I get an InvalidOperation from OpenGL between the "begin 1" and "begin 2" error checks. The [url=http://www.opengl.org/sdk/docs/man/xhtml/glBegin.xml]documentation[/url] says that an InvalidOperation occurs when: I call glBegin() after another glBegin() and before a glEnd() (nope, this is the only time that I call it) I call glEnd() without a glBegin() before it (nope, look at the code) I call one of many gl functions that are not aloud between a glBegin() and a glEnd() (nope, look at the code) There is probably something really obvious that I'm missing.
[QUOTE=Meatpuppet;33861018]I could have singular keys within the base if's, right? The ones that aren't nested. [editline]23rd December 2011[/editline] [cpp] while (App.IsOpened()) { sf::Event Event; switch (Event.Type) { case sf::Event::KeyPressed : if(Event.Key.Code == sf::Key::D) { Velocity x += .25; if(App.GetInput().IsKeyDown(sf::Key::A)) { VelocityX += .25; VelocityX -= .25; } else if(App.GetInput().IsKeyDown(sf::Key::W)) { VelocityX += .25; VelocityY += .25; } else if(App.GetInput().IsKeyDown(sf::Key::S)) { VelocityX += .25; VelocityY -= .25; } } [/cpp] [/quote] Yes. [QUOTE=Meatpuppet;33861018] This leads me to believe I'll have a shitload of code, for every combination. Is that supposed to happen?[/QUOTE] Yes it will probably happen. But as your game gets larger, chances are you're going to make some functions that your events will call instead of huge blocks of code that clutter your events. [QUOTE=Meatpuppet;33861018] [editline]23rd December 2011[/editline] Why isn't this working? [cpp] sf::Event Event; switch(Event.Type) { case sf::Event::Closed : App.Close(); case sf::Event::KeyPressed : if (Event.Key.Code == sf::Key::Escape) App.Close(); else if (Event.Key.Code == sf::Key::D) velocityX += .25; else if (Event.Key.Code == sf::Key::A) velocityX -= .25; else if (Event.Key.Code == sf::Key::W) velocityY += .25; else if (Event.Key.Code == sf::Key::S) velocityY -= .25; break; }[/cpp][/QUOTE] First, I'd like to point out that your sf::Event::Closed case doesn't have a closing "break;" It should be working. Those velocity values should change as soon as when their respective keys are pressed. Remember that the case will be called only as soon as a key is pressed down. Most people would use "Tick()" for movement and use App.GetInput().IsKeyDown(), since it is always being called. If you knew that, what's the issue with it?
So, I'm probably overlooking something in my guide here, but I'm trying to set up this very rudimentary system of squaring and cubing a set of values and saving their results as both lists and sets in Python, but the order it is being saved is very odd. [code] S1 = set([5, 10, 15]) S2 = {x ** 2 for x in S1} S2b = {x ** 3 for x in S1} print(S2) (25, 100, 225) print(S2b) (1000, 125, 3375) [/code] Could someone kindly explain how Python handles the order? I don't understand why it prints 5^2 first in S2, but 10^3 first in S2b.
How can I make it so I can get the Sprites X and Y coords so I can change the effect? [cpp] //Effects sf::PostFX Effect; if (!Effect.LoadFromFile("colorize.sfx")) return EXIT_SUCCESS; Effect.SetTexture("framebuffer", NULL); Effect.SetParameter("color", 1.f, 1.f, 1.f); //Within game loop float X = ? / static_cast<float>(App.GetWidth); //Need to get sprite's velocity in X (called MovingImg, velocity is VelocityX) float Y = ? / static_cast<float>(App.GetHeight); //Same Effect.SetParameter("color", 0.5f, X, Y);[/cpp]
[QUOTE=Meatpuppet;33863089]How can I make it so I can get the Sprites X and Y coords so I can change the effect? [cpp] //Effects sf::PostFX Effect; if (!Effect.LoadFromFile("colorize.sfx")) return EXIT_SUCCESS; Effect.SetTexture("framebuffer", NULL); Effect.SetParameter("color", 1.f, 1.f, 1.f); //Within game loop float X = ? / static_cast<float>(App.GetWidth); //Need to get sprite's X position (called MovingImg) float Y = ? / static_cast<float>(App.GetHeight); //Same Effect.SetParameter("color", 0.5f, X, Y);[/cpp][/QUOTE] If you're using sf::Sprite can't you just call their "GetPosition()" method? [cpp] float x = MovingImg.GetPosition().X / static_cast<float>(App.GetWidth()); float y = MovingImg.GetPosition().Y / static_cast<float>(App.GetHeight()); [/cpp]
[QUOTE=ief014;33863147]If you're using sf::Sprite can't you just call their "GetPosition()" method? [cpp] float x = MovingImg.GetPosition().X; float y = MovingImg.GetPosition().Y; [/cpp][/QUOTE] Sorry, I posted that wrong, and just edited it before you posted this.
[QUOTE=Meatpuppet;33863168]Sorry, I posted that wrong, and just edited it before you posted this.[/QUOTE] I'm guessing your velocity variables are just global variables floating around in your game code. You should consider making a class deriving from sf::Sprite to keep your code a bit cleaner. [cpp] class GameSprite : public sf::Sprite { // Following SFML naming conventions here private: sf::Vector2f myVelocity; public: //Get sprite velocity. const sf::Vector2f & GetVelocity() const { return myVelocity; } //Change sprite velocity void SetVelocity(float x, float y) { myVelocity.X = x; myVelocity.Y = y; } void SetVelocity(const sf::Vector2f & newVelocity) { myVelocity.X = newVelocity.X; myVelocity.Y = newVelocity.Y; } //Add force to sprite's velocity. void ApplyForce(float x, float y) { myVelocity.X += x; myVelocity.Y += y; } void ApplyForce(const sf::Vector2f & force) { myVelocity.X += force.X; myVelocity.Y += force.Y; } //This should be called every tick. //Moves the Sprite by updating the position using velocity. void UpdatePosition() { this->Move(myVelocity); } }; [/cpp] It would be a lot easier on you than keeping track of a bunch of "velocity" variables. Just replace "MovingImg"'s datatype with this class. Since it derives sf::Sprite it will still function as a sprite.
Like this? [cpp] //Moving Sprite sf::Image MovingImage; if(!MovingImage.LoadFromFile("movingobject.png")) return EXIT_FAILURE; class GameSprite : public sf::Sprite { private: sf::Vector2f myVelocity; public: const sf::Vector2f & GetVelocity() const { return myVelocity; } void SetVelocity(float x, float y) { myVelocity.X = x; myVelocity.Y = y; } void SetVelocity(const sf::Vector2f & newVelocity) { myVelocity.X = newVelocity.X; myVelocity.Y = newVelocity.Y; } void ApplyForce(float x, float y) { myVelocity.X += x; myVelocity.Y += y; } void ApplyForce(const sf::Vector2f & force) { myVelocity.X += force.X; myVelocity.Y += force.Y; } void UpdatePosition() { this->Move(myVelocity); } };[/cpp] I'm not that experienced with SFML, and also am fairly new to C++(I understand most things about it)
[QUOTE=Meatpuppet;33863525]Like this? [cpp] //Moving Sprite sf::Image MovingImage; if(!MovingImage.LoadFromFile("movingobject.png")) return EXIT_FAILURE; class GameSprite : public sf::Sprite { private: sf::Vector2f myVelocity; public: const sf::Vector2f & GetVelocity() const { return myVelocity; } void SetVelocity(float x, float y) { myVelocity.X = x; myVelocity.Y = y; } void SetVelocity(const sf::Vector2f & newVelocity) { myVelocity.X = newVelocity.X; myVelocity.Y = newVelocity.Y; } void ApplyForce(float x, float y) { myVelocity.X += x; myVelocity.Y += y; } void ApplyForce(const sf::Vector2f & force) { myVelocity.X += force.X; myVelocity.Y += force.Y; } void UpdatePosition() { this->Move(myVelocity); } };[/cpp] I'm not that experienced with SFML, and also am fairly new to C++(I understand most things about it)[/QUOTE] You should create a new file for the class. "GameObject.hpp" This file should looking similar to this: [cpp] #pragma once #include <SFML/Graphics.hpp> class GameSprite : public sf::Sprite { // Following SFML naming conventions here private: sf::Vector2f myVelocity; public: //Get sprite velocity. const sf::Vector2f & GetVelocity() const { return myVelocity; } //Change sprite velocity void SetVelocity(float x, float y) { myVelocity.X = x; myVelocity.Y = y; } void SetVelocity(const sf::Vector2f & newVelocity) { myVelocity.X = newVelocity.X; myVelocity.Y = newVelocity.Y; } //Add force to sprite's velocity. void ApplyForce(float x, float y) { myVelocity.X += x; myVelocity.Y += y; } void ApplyForce(const sf::Vector2f & force) { myVelocity.X += force.X; myVelocity.Y += force.Y; } //This should be called every tick. //Moves the Sprite by updating the position using velocity. void UpdatePosition() { this->Move(myVelocity); } }; [/cpp] Then in your game code, include your new class: [cpp]#include "GameObject.hpp"[/cpp] (This should be at the top of your game code) And you should use GameObject instead of sf::Sprite. [editline]shit[/editline] Ohhh, I see what you're doing now. You should be using Sprites to keep track of position and other transformations, not just an sf::Image. You need to first create an sf::Image, then let a Sprite access it. [cpp] sf::Image img; if(!img.LoadFromFile("someimagefile.png")) return EXIT_FAILURE; sf::Sprite player; player.SetImage(img); [/cpp] The "player" variable will keep track of sprite-related information, such as Position, Rotation, Scale, Colour, and lots of other useful data. Think of sf::Image as texture data. It keeps information of an image, like all the pixel data. And sf::Sprite is the "textured object", where you can move around the screen, and rotate, and other stuff like that.
I'll just give the file to you, and I'll comment exactly what I'm asking for. Hold on. [editline]23rd December 2011[/editline] [url]http://www.gamefront.com/files/21112901/flying_obama.cpp[/url] [editline]23rd December 2011[/editline] Sorry for all the troubles by the way.
[QUOTE=Ziks;33862057]In OpenGL, should I be able to call glBegin() and then glEnd() immediately after with no errors? Here's what I'm doing: [csharp]ErrorCheck( "begin 1" ); GL.Begin( BeginMode.Quads ); GL.End(); ErrorCheck( "begin 2" );[/csharp] I get an InvalidOperation from OpenGL between the "begin 1" and "begin 2" error checks. The [url=http://www.opengl.org/sdk/docs/man/xhtml/glBegin.xml]documentation[/url] says that an InvalidOperation occurs when: I call glBegin() after another glBegin() and before a glEnd() (nope, this is the only time that I call it) I call glEnd() without a glBegin() before it (nope, look at the code) I call one of many gl functions that are not aloud between a glBegin() and a glEnd() (nope, look at the code) There is probably something really obvious that I'm missing.[/QUOTE] Fixed, the problem was that I was setting a sampler to use an invalid texture unit. I had assumed that (int) TextureUnit.Texture0 = 0, (int) TextureUnit.Texture1 = 1, etc.
transparency is usually handled in deferred renderers by doing some depth testing and just rendering the transparent object afterwards using forward rendering. If you want it to be lit, take into account the nearest light or something. Another option is to render one pass per light. That is, you'll be rendering the entire scene over for each light. The last option is lightmaps, you can run a tool that pre-renders all the lighting into textures that you overlay on every surface in the world. If you want to keep things simple, though, just create vectors between the camera and each light and compare the lengths.
Using the code below to link to a different scene, how would I go about incorporating transitions? I'm using AS3. [CODE] welcome_enter.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene); function fl_ClickToGoToScene(event:MouseEvent):void { MovieClip(this.root).gotoAndPlay(1, "Navigation"); } [/CODE] As I understand (I have near enough no knowledge of AS3), I'll need to import the transitions classes then add another event for when the button is clicked? I truly appreciate any help :smile:
[del]How can I reference Form1 in Form1.cs, so I can access the controls from within a static method?[/del] Not sure I like it, but I solved it by just passing the Form1 reference to the static Form1 method.
can someone help me with GLSL? im currently using: [code] #version 120 uniform sampler2D framebuffer; #define glaresize 0.008 // 0.008 is good #define power 0.5 // 0.50 is good void main() { vec4 sum = vec4(0); vec4 bum = vec4(0); vec2 texcoord = vec2(gl_TexCoord[0]); int j; int i; for( i= -2 ;i < 2; i++) { for (j = -1; j < 1; j++) { sum += texture2D(framebuffer, texcoord + vec2(-i, j)*glaresize) * power; bum += texture2D(framebuffer, texcoord + vec2(j, i)*glaresize) * power; } } if (texture2D(framebuffer, texcoord).r < 2.0f) { gl_FragColor = sum*sum*sum*0.0080+bum*bum*bum*0.0080+ texture2D(framebuffer, texcoord); } }[/code] but its not givving me bloom, i tried changing the values but it just messes teh image up. And I cant use renderTargets as my computer doesnt like them (intel)
Is there any clean way to get a WndProc's wParam to not send a-z as A-Z, regardless of shift/capslock? I cam up with this: [cpp] if(msg.message == WM_KEYDOWN) { int keyCode = (int) msg.wParam; //To fix this, if it's a capital letter, we downgrade it. if(keyCode >= 65 && keyCode <= 90) { keyCode += 'a' - 'A'; } Key_Event( keyCode, true); } [/cpp] Where Key_Event takes an ascii-int for a letter. However, I'm worried that this hack will cause problems with other keys/etc. and I'm wondering if there's a proper way to do this.
tolower(int c) and toupper(int c)
[QUOTE=NovembrDobby;33869809]tolower(int c) and toupper(int c)[/QUOTE] Whelp, that worked out pretty well. Handles 0-9 fine, but "{/[" (123 or 91) comes across as 219, though that's not tolower's fault. Do I have to make special handling for keys like {, ;, ., etc?
[QUOTE=Lord Ned;33870086]Whelp, that worked out pretty well. Handles 0-9 fine, but "{/[" (123 or 91) comes across as 219, though that's not tolower's fault. Do I have to make special handling for keys like {, ;, ., etc?[/QUOTE]I'm pretty sure those functions just add and subtract 32 from the character (respectively), but don't quote me on that.
[del]C# How can I detect if an arrow key is pressed down on a form when the currently focused control doesn't matter?[/del] Have to set KeyPreview in the forms properties, then just use the KeyPress Event.
So, in a class file, I'm using [cpp] int Spaceship::ImageName(char imagename[20]) { char *str; str = imagename; sf::Image shipimage; if(!shipimage.LoadFromFile(str)) return EXIT_FAILURE; sf::Sprite shipimg(shipimage); } [/cpp] and in the main file, I'm using [cpp] shipimg.SetCenter(0, -250);[/cpp] But it says "'shipimg' was not declared in this scope'". Shipimg was declared in the header file?
[QUOTE=Meatpuppet;33876873]So, in a class file, I'm using [cpp] int Spaceship::ImageName(char imagename[20]) { char *str; str = imagename; sf::Image shipimage; if(!shipimage.LoadFromFile(str)) return EXIT_FAILURE; sf::Sprite shipimg(shipimage); } [/cpp] and in the main file, I'm using [cpp] shipimg.SetCenter(0, -250);[/cpp] But it says "'shipimg' was not declared in this scope'". Shipimg was declared in the header file?[/QUOTE] But it was declared in the function, which means it goes out of scope when the execution of that function ends.
[QUOTE=Octave;33877244]But it was declared in the function, which means it goes out of scope when the execution of that function ends.[/QUOTE] Oh, facepalm. How can I keep that function, but still have main() be able to call it?
[QUOTE=Meatpuppet;33878160]Oh, facepalm. How can I keep that function, but still have main() be able to call it?[/QUOTE] You could declare shipimg outside of the function in the header file.
[QUOTE=Octave;33878200]You could declare shipimg outside of the function in the header file.[/QUOTE] Gonna have to figure out that. Thanks though [editline]24th December 2011[/editline] now it's [cpp] // picture int ImageName(char imagename[20]); sf::Image shipimage; if(!shipimage.LoadFromFile(ImageName)) return EXIT_FAILURE; sf::Sprite shipimg(shipimage);[/cpp] and [cpp]int Spaceship::ImageName(char imagename[20]) { char *str; str = imagename; return str; }[/cpp] Now it says "shipimage" is not a type. What?
[QUOTE=Lord Ned;33869545]Is there any clean way to get a WndProc's wParam to not send a-z as A-Z, regardless of shift/capslock? I cam up with this: if(msg.message == WM_KEYDOWN) { int keyCode = (int) msg.wParam; //To fix this, if it's a capital letter, we downgrade it. if(keyCode >= 65 && keyCode <= 90) { keyCode += 'a' - 'A'; } Key_Event( keyCode, true); } Where Key_Event takes an ascii-int for a letter. However, I'm worried that this hack will cause problems with other keys/etc. and I'm wondering if there's a proper way to do this.[/QUOTE] Virtual key codes aren't characters. A-Z just match the same values. They mean literally the key, not the character it produces. You might want to look at WM_CHAR, or sort it on your own elsewhere.
[QUOTE=Meatpuppet;33878270]Gonna have to figure out that. Thanks though [editline]24th December 2011[/editline] now it's [cpp] // picture int ImageName(char imagename[20]); sf::Image shipimage; if(!shipimage.LoadFromFile(ImageName)) return EXIT_FAILURE; sf::Sprite shipimg(shipimage);[/cpp] and [cpp]int Spaceship::ImageName(char imagename[20]) { char *str; str = imagename; return str; }[/cpp] Now it says "shipimage" is not a type. What?[/QUOTE] You can put everything but "sf::Image shipimage" in the function.
[QUOTE=Meatpuppet;33878270]Gonna have to figure out that. Thanks though [editline]24th December 2011[/editline] now it's // picture int ImageName(char imagename[20]); sf::Image shipimage; if(!shipimage.LoadFromFile(ImageName)) return EXIT_FAILURE; sf::Sprite shipimg(shipimage); and int Spaceship::ImageName(char imagename[20]) { char *str; str = imagename; return str; } Now it says "shipimage" is not a type. What?[/QUOTE] try this in the header: [code] class Spaceship { private: std::string imageName; sf::Image myImage; sf::Sprite mySprite; public: int loadImage(const std::string& path); }; [/code] and this later (in cpp or whatever): [code] int Spaceship::loadImage(const std::string& path) { imageName = path; int code = myImage.LoadFromFile(imageName)); mySprite = sf::Sprite(myImage); return code; } [/code]
[QUOTE=Philly c;33878369]Virtual key codes aren't characters. A-Z just match the same values. They mean literally the key, not the character it produces. You might want to look at WM_CHAR, or sort it on your own elsewhere.[/QUOTE] 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.
Sorry, you need to Log In to post a reply to this thread.