Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Serapth

Pages: 1 ... 5 6 [7]
91
General / SFML Complete Game Tutorial
« on: September 11, 2011, 01:04:55 am »
Hi everybody,

Thanks for the kind words.  Section 5 is being written as we speak ( all sample code for 5 & 6 is complete ).  I am currently doing a bit of a revision based on some feedback I've received so that distracted things a bit.

Also, death nearly laid her hands on me  ( Ok... I got a flu ), so writing cohesively hasn't been my strong suit the last couple days.  Should have part 5 up very soon, most likely Monday at the latest, perhaps tomorrow if my immune system decides to stop sucking.  It's kinda funny, I am able to code sick, but stringing two cohesive sentences together seems to be beyond me!


EDIT: BTW, did I post this thread to the wrong forum?  If so, sorry.  I didn't post to Announcements based on the fact it's not "done" per say.

92
General / SFML Complete Game Tutorial
« on: September 09, 2011, 02:47:10 pm »
Thanks for pointing that out, it has been fixed now.

Windows Live Writer, which is otherwise a very nice blogging tool, has this horrible glitch where it will attempt to turn a + in the title into a URL.  So every post with forbidden characters in the title I need to manually edit the page name.  I missed that one. :(

93
General / SFML Complete Game Tutorial
« on: September 09, 2011, 12:16:26 am »
One of the tenants I am working upon is to write code that initially fits, but in later chapters revist it to fit changing circumstances.  This is meant more as a learning exercise than as a coding template.

For example, in Part 4, I introduce the VisibleGameObject class, which owns an sf::Image class.  Then I present a PlayerPaddle class, which loads an image to represent the player's paddle.  In a future chapter, I will present an AI Paddle class, which will result in the duplicate loading of the same Image file, and will then present a class to rectify this inefficiency.

I hope that made sense.


I also should have named Gameloop() as GameloopIteration() or something similar, as the current name is misleading.  I regret how I structured that aspect of the code for clarities sake and will probably refine it.  Making the initial Game class static also probably introduced a level of complexity that could have been avoided, although by the end of the process, I think it will still prove to be the right decision.

94
General / SFML Complete Game Tutorial
« on: September 09, 2011, 12:09:46 am »
I have been working on a tutorial series on using SFML 1.6 with Visual Studio 2010 to create a complete game from scratch.

One of the things I often see is when new developers share their code, the structure is absolutely horrible.  Part of this is as a result of learning from code samples that are meant to concisely demonstrate the usage of the library involved, not how to make an actual game.  Many other beginner samples are from books, where being concise is one of the most important aspects. There seem to be very few examples out there that actually explain how to bridge the gap between various library features and an creating an actual game.

That is what I am trying to provide with this example.  It is long, 5 chapters already and frankly nowhere near complete and the end result is going to be a glorified pong clone.  That said, along the process I try to teach the basics of object oriented programming.  Additionally, initial setup and configuration seems to be one of the major stumbling blocks for new developers in C++, so I spend a good deal of time focusing on that in detail.


Anyways, if you are new to SFML and are just learning C++, you are my target audience.

If you are a C++ expert and see a glaring flaw in what I have written, let me know!

Hopefully this series is useful to new developers.  Please let me know what you think.

A Game From Scratch: C++ Edition

95
General / Just the Basics
« on: September 03, 2011, 05:28:10 am »
Quote from: "eXpl0it3r"
Quote from: "manasij7479"
Then you'd 'love' to open the samples folder !


About your Code::Block problem; I haven't had problems in the past when I used it, although that stuff is really confusing at the beginning, mostly because NONE of those basic learning-C++-books teach how to use libraries.



The single biggest problem(using CB) that is going to be a gigantic show stopper for a new developer, is that CodeBlocks ships with a version of MingW that is incompatible with SFML.  It's a fairly easy thing to resolve if you know what you are doing, but this goes exactly contrary to the whole being a new developer thing...


A thousand fold more confusing is the fact the "wizard" simply doesn't work.  When you figure that "wizards" are there mostly for new developers, that's what makes it more confusing.  I by no means blame this on SFML, but they are very legit pitfalls for new and experienced developers.

96
General / better tutorial for SFML?
« on: August 29, 2011, 01:33:55 am »
Quote from: "metulburr"
so whats wrong with this code? it does the same?


You are using switch statements wrongly and are using multiple ifs when you should have just a single.

Quote

i was initially asking though that the front of the "image" always maintain 'W'
so if the user held S the ship goes down, the ship turns downwards, and if the user held D the ship turned right and moved right? all the times i tried the ship moves in the direction that i wanted but doesnt stop turning?


Ok, I read that like 5 times and I still am not really sure what you are asking.  If you want anything beyond basically moving around the screen, you are going to need to implement a direction vector and velocity.  If you want to change it so input isn't one to one ( ie, a keypress == a move ), you need to switch your input logic substantially.

97
General / better tutorial for SFML?
« on: August 29, 2011, 12:55:20 am »
Quote from: "OniLink10"
Quote from: "Serapth"
Your logic is heavily flawed, in a game loop you should only poll for a single event.  Give me a minute and I'll redo your code to be a bit cleaner/more legible.
Except that is an EXTREMELY dumb idea (poll for a single event). You are supposed to do a while loop for event handling. If you don't, then it can cause your program to lag due to too many events being stockpiled. In fact, on certain operating systems (certain versions of Windows come to mind), you MUST poll as many events as possible per frame, or the program slows to a crawl.


Very well, I was going off something I thought I had read recently in the documentation that SFML worked at an event per loop, but either way, it's really not a big deal.

As Lo-X already wrote, simply change the if to a while and the event stack will empty itself.  Edited example to use while instead of if.


As to what I said regarding his initial code, I was actually very poor in my wording anyways.  It was not the handling more than one event that was flawed, it was handling events in more than one place and polling events multiple times per pass that was flawed and I addressed in my example.

98
General / better tutorial for SFML?
« on: August 29, 2011, 12:44:41 am »
Hmmm, perhaps comments might help more.  Same code commented:


Code: [Select]
// SFMLTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main(int argc, char ** argv)
{
sf::RenderWindow window;   // Declare a window object
window.Create(sf::VideoMode(1024,768,32),"Test"); // Create the window, setting the resolution and pixel depth


sf::Image img; // Declare an image object
if(!img.LoadFromFile("ship.png")) return 42;  // Load our image from file, if it fails, exit the program

sf::Sprite sprite(img);  // Declare a sprite, and in it's constructor assign an image to it.  There can be multiple sprites to a single image

sprite.SetX(( 1024/2 - img.GetWidth() /2)); // Position the sprite in the middle of the screen
sprite.SetY((768/2 - img.GetHeight() /2));

//Gameloop

bool done = false;  // Boolean variable flag that will tell us when to exit the program


while(!done)  // Loop ( "game loop" ) forever, or until the "done" flag is set to true
{
sf::Event myEvent;  // declare an event

while(window.GetEvent(myEvent)) // GetEvent returns true if there is a new event, if there is an event, handle it, otherwise proceed to drawing
{
switch(myEvent.Type) // Switch ( think a branching if statement ) on the type of event we are processing
{
case sf::Event::Closed: // If the event is a close type, set the done flag to true so we exit next pass through the loop
done = true;
break;  // You need a break statement for every case: condition, or the switch will "fall through" and continue processing

case sf::Event::KeyPressed: // Is it a key press event?
{
switch(myEvent.Key.Code)  // If so, which Key?
{
case sf::Key::W:   // Handle the various keys
{
sprite.Move(0,-1);  // Move up 1 pixel
break;
}
case sf::Key::A:
{
sprite.Move(-1,0); // Move left
break;
}
case sf::Key::S:
{
sprite.Move(0,1); // Move down
break;
}
case sf::Key::D:
{
sprite.Move(1,0);  // Move right
break;
}
case sf::Key::Q:
{
sprite.Rotate(-1.f); // Rotate 1 degree left
break;
}
case sf::Key::E:
{
sprite.Rotate(1.f); // Rotate 1 degree right
break;
}
}
break;
}
}
}

// done handling events
window.Clear(sf::Color::White);   // Clear the screen to white
window.Draw(sprite); // Draw your sprite to the screen
window.Display(); // Display the screen
}// Now we are done "one" pass through the game loop, continue to next pass getting input, drawing screen, etc... until done is true

window.Close(); // Close the window
return 0; // Return "everythingAOK code
}

99
General / better tutorial for SFML?
« on: August 29, 2011, 12:34:54 am »
Quote from: "metulburr"
@Serapth
thank you very much, maybe i could make sense of (why things are there) with your rewritten code



Here you go, for the record its a quick hack job.  The nested switches get a little messy and should be reorganized eventually.

Also, there is no bounds checking to the corner of the screen ( when you hit the screens edge, it will probably crash ) and rotation is from the top left of the sprite instead of the center, but fixing both of these issues would have just complicated things, both things should be easy enough for you to fix later.


Code: [Select]


// SFMLTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

int main(int argc, char ** argv)
{
sf::RenderWindow window;
window.Create(sf::VideoMode(1024,768,32),"Test");


sf::Image img;
if(!img.LoadFromFile("ship.png")) return 42;

sf::Sprite sprite(img);
sprite.SetX(( 1024/2 - img.GetWidth() /2));
sprite.SetY((768/2 - img.GetHeight() /2));

//Gameloop

bool done = false;
while(!done)
{
sf::Event myEvent;

while(window.GetEvent(myEvent))
{
switch(myEvent.Type)
{
case sf::Event::Closed:
done = true;
break;

case sf::Event::KeyPressed:
{
switch(myEvent.Key.Code)
{
case sf::Key::W:
{
sprite.Move(0,-1);
break;
}
case sf::Key::A:
{
sprite.Move(-1,0);
break;
}
case sf::Key::S:
{
sprite.Move(0,1);
break;
}
case sf::Key::D:
{
sprite.Move(1,0);
break;
}
case sf::Key::Q:
{
sprite.Rotate(-1.f);
break;
}
case sf::Key::E:
{
sprite.Rotate(1.f);
break;
}
}
break;
}
}
}

// done handling events
window.Clear(sf::Color::White);
window.Draw(sprite);
window.Display();
}

return 0;
}

100
General / better tutorial for SFML?
« on: August 29, 2011, 12:07:02 am »
Your logic is heavily flawed.  Give me a minute and I'll redo your code to be a bit cleaner/more legible.

101
General / Tutorial - Window - Opening a window - doesn't work
« on: August 28, 2011, 11:56:22 pm »
The problem is for Visual Studio 2010 at least, the build process is a bit broken, and the Debug-Static project settings build incorrectly.  Even though you build them yourself, some of the static libs get compiled with the wrong linker flags.  A single lib linking to the wrong runtime, or not recompiled for VC2010 is going to be a showstopper.


Here is the easiest way to fix it, if you want to use static libraries.

Import the solution from SFML-1.6-sdk-windows-vc2008 in Visual Studio 2010.

Delete all of the example projects from your solution ( to make your life a hell of a lot easier )

Now for each of the SFML libraries, right click the project, select Properties.  Make sure "Configuration:" is set to Active(Debug static).

Then select Configuration Properties-> Code Generation, on the right find Runtime Library and make sure it is changed to Multi-threaded Debug  ( instead of Multi Threaded Debug DLL as it is now ).

Rebuild your libraries.  After the build is completed, your static libraries will be located at <Project Root>\SFML-1.6\lib\vc2008.

Copy these 5 freshly created libs to your new project, and make sure it's runtime setting it set the same.  Keep in mind, you will also need to build for static release as well when you are ready to deploy.

If you run into problems, here are the libs precompiled for you.  Just add them to your project, make sure your Runtime Library is set right and you should be good to go.



Or save yourself a ton of effort and link to the dynamic libs. :)

102
General / C++ SFML Linking / Unknown Problem
« on: August 18, 2011, 03:18:48 am »
Quote from: "VisualProgrammer"
I didn't say system32, i said system.


Same deal, except that system has been deprecated.  System is simply the legacy version of System32 from the win32 days.

Same end result.

103
General / C++ SFML Linking / Unknown Problem
« on: August 18, 2011, 12:38:41 am »
Oh trust me, you don't want to put development libraries in the system32 folder, it is going to make your debugging process an absolute nightmare!  It adds a whole layer of "which dll am I running???"

Granted, dll loading preference goes
1) implicitly defined locations
2) executables run directory
3) system32 directory
4) in system path

However, sometimes figuring out just where the heck the executable run directory actually is can be a nightmare!  

By putting them in System32, it is going to be run by default if you made a mistake.

104
General / C++ SFML Linking / Unknown Problem
« on: August 17, 2011, 02:14:32 am »
Part of a tutorial I am writing, but isn't quite ready for prime time has exactly the answers you are looking for.

I can use you as a gueinea pig, let me know if it helps you out.

Part One

Part Two


Visual Studio 2010 has a few quirks for a beginner developer to get using SFML.  I hope its not an issue to provide compiled for 2k10 binaries?

105
General / Cant use sfml. I am sad.
« on: August 16, 2011, 11:59:18 pm »
I was curious so I gave this a shot and managed to get exactly the same response.

http://flexapic.com/g.ashx?id=7433


Recompiled the SFML and SFML.net DLLs and the error reoccured.

Then I considered bitness, went into the opengl sample and reconfigured it to X86 and everything worked fine.

So either you need to rebuild all the DLLs for 64bit, or compile you code as X86, your call.

To change the compiler settings go:

Right click your project in Solution Explorer
Select Properties
Select Build
Change Platform Target: to X86

Like this:

http://flexapic.com/g.ashx?id=7435

Pages: 1 ... 5 6 [7]