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

Author Topic: Lethn's Programming Questions Thread  (Read 61229 times)

0 Members and 3 Guests are viewing this topic.

Gobbles

  • Full Member
  • ***
  • Posts: 132
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #75 on: August 02, 2013, 05:44:41 am »
I assume you mean that when you press Left, your health doesn't update and the if statement you are referring to is the one below.

if ( sf::Keyboard::isKeyPressed ( sf::Keyboard::Left ) )

    {
        health.setSize ( sf::Vector2f ( 100, 20 ) );
    }


while (window.isOpen())
{

sf::Event event;
while (window.pollEvent(event))
{
 

Your issue is that you can't access the the code once inside the while loop, as it only happens before hand.
In order to fix this, move the if statement to inside the while loop so it gets hit when you make the key press.

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #76 on: August 02, 2013, 10:34:12 am »
Ah yes, thanks! I seem to get the overall idea now I just make silly mistakes, when I was setting it all up I forgot that i needed to draw the rectangle at the end to make it appear on the screen lol >_<

Edit: Works fine now, I just need to tweak it some more, I thought I'd try something more fun and graphic based because I was getting tired of C++ :D
« Last Edit: August 02, 2013, 11:08:27 am by Lethn »

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #77 on: August 03, 2013, 04:26:48 pm »
By the way guys, I'm having a look at getting animation into my SFML code, if you know of any good tutorials out there that explain things right I'd like to have a look at them. I also have a question about it, I keep hearing that sprite sheets are commonly used in 2D games and while I have no problem constructing them I have a piece of software that allows me to create some really nice animations and just easily export them as image sequences.

Is there any particular differences between me using image sequences or sprite sheets in the code or are these just two different ways of implementing animations? I ask this because being able to use image sequences would really help out my games and make them a lot less static because I could animate absolutely everything on the screen.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Lethn's Programming Questions Thread
« Reply #78 on: August 03, 2013, 04:29:43 pm »
What are image sequences, or how do they differ from sprite sheets?

You could have a look at Thor's animations to see how a possible implementation looks like, or directly use it in your projects.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #79 on: August 03, 2013, 06:30:37 pm »
Well I can use this software called pencil, it's really nice to use ( for me at least :D ) and what it can do is either export my drawn frames as movie files or as a series of .pngs etc. the software uses the term 'image sequence'. I know how to do all the animation because I've been learning drawing way before I just need to understand it in the programming context.
« Last Edit: August 03, 2013, 06:32:58 pm by Lethn »

The Hatchet

  • Full Member
  • ***
  • Posts: 135
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #80 on: August 03, 2013, 08:02:49 pm »
sprite sheets and image sequences are one in the same I'm pretty sure.  spritesheet is just a generic term to call any image file that contains multiple sprites on it, be it an animation sequence, tilesets, sprites for world objects, etc.

Barlog

  • Guest
Re: Lethn's Programming Questions Thread
« Reply #81 on: August 03, 2013, 09:14:02 pm »
Image sequence and Spritesheets only have one thing in common. Either of them is graphical file in some format (png, jpg, tif, gif, etc).

For the rest they differ in following.
0. Images sequence (as output from Pencil) is the set of n files, where each one is one frame of animation.
1. Spritesheet is collection of usually similar in size images in one file. It could be animation, or image data for terrain tiles, or graphics for your game items.

From a programming perspective they differ in nearly same way.
0. For images sequence you must use as many sf::Textures as you have files. E.g. If you have 10 frames (10 files), then you need ten sf::Texture variables (or one vector of 10 sf::Textures) to hold image data.
1. For spritesheets you declare and define one sf::Textire variable and use different offset of TextureCoordinates to draw a sprite.

Hope this clarify things a bit.

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #82 on: August 04, 2013, 07:11:28 am »
thanks guys that's actually cleared things up a lot, my only fear now is the idea of having to add 30 frames any times I want to put a nice animation into my game, is there any way to batch add them in or is this just one of the more painful aspects of programming and why everyone keeps their animations really simple?

If I figure this out I'll be able to have some really nice building animations in my games etc. so I'm quite happy to get it done I just hope there are ways to make it less tedious, would the C++ break function be something to look at?

Edit: nope, break is the wrong one I'm thinking of but I remember there being a statement that lets you execute several other pieces of code in a batch which would probably be perfect for animations, hatchet mentioned it to me at one point.
« Last Edit: August 04, 2013, 07:16:55 am by Lethn »

Gobbles

  • Full Member
  • ***
  • Posts: 132
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #83 on: August 04, 2013, 07:20:54 am »
This is where setting up an animation class for a Texture Atlas(a sprite sheet) really comes in handy.
Creating a class that will allow you to load in a new texture, give the animation a name, how many frames, whether it should auto-repeat(like an idle animation) or not (like an attack animation) and also set up the sprite rectangle to use for each frame will also be handy.

Animations are complex stuff and setting them up varies greatly on what you need. Its up to you as the programmer to decide what you need and how to implement it. Such is what game programming is all about after all.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Lethn's Programming Questions Thread
« Reply #84 on: August 04, 2013, 03:20:54 pm »
so I'm quite happy to get it done I just hope there are ways to make it less tedious, would the C++ break function be something to look at?
If you mean the break keyword -- no, again. If you haven't learned its meaning by now, it's more than time! Don't even start with SFML as long as you don't know basic control structures. Apparently you have still not considered our advice to learn C++ :(

but I remember there being a statement that lets you execute several other pieces of code in a batch which would probably be perfect for animations, hatchet mentioned it to me at one point.
Functions? :o

Seriously, learn the language. You're still guessing around -- what you need is an overview over language features and the knowledge how to combine them. You have the imagination that there is exactly one C++ feature for a specific task, which is completely wrong. Every task requires a combination of dozens of language features. And unless you learn how to use your tools, you won't be able to combine them and you'll still be guessing in a year...

This is where setting up an animation class for a Texture Atlas(a sprite sheet) really comes in handy.
Creating a class that will allow you to load in a new texture, give the animation a name, how many frames, whether it should auto-repeat(like an idle animation) or not (like an attack animation) and also set up the sprite rectangle to use for each frame will also be handy.
Like thor::Animator I mentioned earlier. But this requires again basic C++ knowledge.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #85 on: August 07, 2013, 05:23:02 pm »
*currently reading through variables and basic types*

You can keep claiming bugger all about what I'm reading all you like Nexus, doesn't mean any of it's true. As for the way I'm treating SFML, from my learning so far i've found it's not necessarily just C++ and it's not by itself either ( I also meant statements not functions, everybody forgets things >_> ). It's more like a mod or an addon to C++ more than anything from what I've looked at and makes a lot of game/media related tasks a lot easier.

Thanks to peoples comments I think I have a rough idea of how to get animations in but I'll keep reading through the C++ book because as I've said before it's making things a lot easier to understand, particularly with how this one is teaching the vocabulary as you progress.

Note: I looked through the PM and I found it, switch() statement is the one I was thinking of! I'm thinking of using that when I learn how to do everything properly.


Edit: By the way, here's a small preview of the type of thing I'm going to be testing out animation wise this type of stuff can be from 30 - 200 frames long or even longer depending on what you want to do: http://www.swfcabin.com/open/1375887388
« Last Edit: August 07, 2013, 05:57:29 pm by Lethn »

Semicolon

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #86 on: August 08, 2013, 10:23:59 am »
*currently reading through variables and basic types*

...

If you'd like videos instead (I know I do), I started out learning programming through xoax. The videos are a bit sleep-inducing but still good.

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #87 on: August 08, 2013, 11:11:09 am »

... As for the way I'm treating SFML, from my learning so far i've found it's not necessarily just C++ and it's not by itself either ( I also meant statements not functions, everybody forgets things >_> ). It's more like a mod or an addon to C++ ...


I mean no offense, but that is one of the silliest things a beginner can think about C++; SFML isn't a mod or an addon to c++, it doesn't change c++, but rather uses it. C++ isn't this or that implementation, it is a language, a set of rules for syntax and grammar and so on. Modding C++ involves writing further code in its compiler.. :p SFML is as much of an addon as the very code you write yourself :p

Sorry if this comes out in a bad way, I don't mean to offend, really ^^

Lethn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: Lethn's Programming Questions Thread
« Reply #88 on: August 08, 2013, 01:01:12 pm »
lol! I'm not offended if it's true, it's if you're talking a load of rubbish and expect me to accept it that I'd get offended :P. I guess it must be because I'm a noob still but honestly, this is my view on it, without C++ code this thing doesn't work, you can't for instance, ditch the curly braces or say no to insertion operators and that's all C++ from what I've seen it's only C++ that works by itself.

If you just wrote some sf::Text stuff all by itself then you'd get error messages everywhere wouldn't you? You still need to even have the int main() to have it all working, that's what makes me think of it as an addon/mod. Yes, it's all coded entirely seperately, the person who made it had to have done it separately but in the end it looks to me like it's been written so that you need to have C++.

I'm aware as well from looking at the basic features though that it can be used in python/ruby etc. but in the end you still have to have the basic programming languages to make the thing work properly you can't just have pure SFML code and expect the program to work right?
« Last Edit: August 08, 2013, 01:03:24 pm by Lethn »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Lethn's Programming Questions Thread
« Reply #89 on: August 08, 2013, 02:40:42 pm »
Yes, because SFML is a library, not a programming language.  It's just some code people wrote in C++ that you can use in your own C++ program.  It is in no way an extension of what the C++ language itself offers.

Maybe an analogy would help: saying SFML is a mod or extension C++ is like saying the King James Bible is a mod or extension of English.  Trying to read the Bible and learn English at the same time is just silly.  At best you'll come out of it with a very twisted understanding of both.  You should be starting off with a far simpler and more newbie-friendly book like See Spot Run (or in C++, a Hello World! program, reversing a string, implementing some basic sorting algorithms, etc, NOT a window-based program with user input and 3D graphics and whatnot using SFML).

 

anything