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 - Ztormi

Pages: 1 2 [3] 4 5
31
I believe I figured out what's happening here. You are setting your sprites' position twice. You already set the position of your sprites on update. Then on Draw, you apply entity's current transform (position) into renderstates.  SFML.Graphics.Sprite is a Transformable too so you are actually drawing sprite into entity's position + sprite's position. Result is that the sprites position property doesn't represent what you see on screen, it's real position is actually to the left but it's drawn more to the right.

If you comment states states.Transform *= this.Transform; it works. But I'd suggest you to implement your own GetGlobalBounds for entities/physicsobjects instead. Chances are you're gonna need a different bounding box from the sprite anyway (ie. sprite is not cropped or has empty space around it) so I think it'd be a good idea to do that first. Separating things like this from sprites and drawing is a good idea anyway imo.

32
SFML projects / Re: Crush!
« on: February 16, 2015, 11:41:50 pm »
Looks good, and the sound effects are awesome  ;D

Those water effects are absolutely gorgeous!

33
General / Re: How to draw a simple sprite with OpenGL?
« on: February 16, 2015, 09:50:15 am »
Yes it is.

I believe AlexAUT is referring to the usage of glBegin, glVertex and glEnd which is an ancient way of drawing things. You can learn more about this on http://gamedev.stackexchange.com/questions/34108/opengl-vbo-or-glbegin-glend
http://www.songho.ca/opengl/gl_vertexarray.html and
http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Table-of-Contents.html

34
Graphics / Re: Problem with layers in tilemap system.
« on: February 10, 2015, 02:28:23 pm »
Nope. JPEG doesn't support alpha channel.
Besides that having compression on the image will fully ruin the pixel image, e.g. one can't even mask it now.

If you click it it will open the original PNG image  ;)

35
Graphics / Re: Problem with layers in tilemap system.
« on: February 10, 2015, 11:16:28 am »
Are you using single vertex array for all layers? AppendTile-method sure doesn't seem to support it. Looks to me like you are unintentionally replacing quad instead of adding a new one.

36
SFML projects / Re: Screenshot Thread
« on: February 04, 2015, 09:11:45 am »
I've been looking forward to making my own version of legendary Steel Panthers games. It's a series of tactical turn based hex strategy games or even combat simulations, most of them taking place in WW2. The series is pretty much forgotten and there are some parts of the game that haven't aged particularly well in my opinion. Since noone else is doing it, I decided to start working on spiritual successor myself. Obviously this is in very early stage of development, but I'm quite happy with the terrain renderer I've been working on so far. Bump maps and shadows are created with shaders and they require a bit of adjustments. The project is using .NET bindings, no other libraries except Newton-King's JSON parser.




37
Graphics / Re: Sprite Transformation Batching
« on: February 02, 2015, 03:02:16 pm »
Assuming all tiles share the same tileset, only one draw call is necessary.

You do realize that drawing with single call doesn't do anything to increase performance if you are iterating thousand+ elements every single frame?

Like grok said. You wouldn't probably notice any difference in performance if you are drawing them during the iteration, as opposed to adding them to empty vertex array each frame and drawing the array after that.

38
Graphics / Re: Sprite Transformation Batching
« on: February 02, 2015, 01:50:13 pm »
...snip...

You'll want as few loops as possible in your drawing methods. It also doesn't make much sense to me to rebuild the vertex array each frame. You can draw vertex arrays by giving the count of vertices you want to draw, starting from certain index. I'd personally just store the map in a single vertex array unless it's absolutely huge. Then I'd draw visible vertices row by row.

This way you can update texcoords and colors only when necessary, without rebuilding vertexarray.

In draw:
for each row of tiles in screen
  draw num_tiles_in_screen.x * 4 vertices
  from first_tile_in_screen.x * 4 + num_tiles_in_screen.x * row * 4 + (totaltiles.x - num_tiles_in_screen.x) * 4 * row
 

edit: remember to clamp num_tiles_in_screen

39
DotNet / Re: Loading textures from a zip archive
« on: January 29, 2015, 04:46:52 pm »
I'm going to take a wild guess and say this will fix it http://stackoverflow.com/questions/8741474/returning-a-stream-from-file-openread

40
General / Re: Terrain Layers
« on: January 29, 2015, 10:50:47 am »

Chunking can be okay/nesecary. I mean if your field of view is 100th of the whole map, you really don't want to draw everything, but instead chunk things up and only use the chunks around the players position.


Well sure, I'd probably chunk the tilemap after I notice considerable performance problems with drawing.

Edit:

If you do have a working solution for drawing tilemap with chunks, just use it. But the point is, I don't think it's worth the hassle to try to figure out generic solution on how to stuff all the objects into single vertex array. Rather just split the rendering into logical components (ie. tilemap,sceneries, animated entities).

41
General / Re: Terrain Layers
« on: January 29, 2015, 10:32:32 am »

If I understand you right Ztormi, you would suggest a vertex array that covers the whole area the player can see? But if I move to one side, this would mean a rebuild of the whole array. Or did you have something else in mind?


No, I meant you forget the chunks and just draw the whole map, layer by layer.

Like Jesper Juhl mentioned, the method of updating and keeping track of your drawable items is probably more perfomance intensive operation than drawing itself.

Logic would go like this:

Sprite refers to a drawable object which's position is not tied into a tile.

- I have two classes, World, Renderer
- World notifies Renderer when tile is changed
- World notifies Renderer when sprite is created
- World notifies Renderer when sprite is changed
- World notifies Renderer when sprite is destroyed
- Renderer has two vertexarrays, tilelayer and spritelayer
- On draw, both vertexarrays are drawn in correct order

Tilelayer vertex array is really straightforward. However, the vertex array containing sprites is a bit trickier. For this to make sense, I scratched up an example. I use sfml.net with C# because that's how I roll.

Sprites:
(click to show/hide)

Renderer:
(click to show/hide)

Notice a problem here?

Every time we remove object from MappedVertexArray we'll have to rearrange all the vertices. Again, referring to Jesper Juhl's post, you'll have to profile if this approach is worth it. Or would it be faster to just have a list of sprites in screen and draw them one by one.




42
General / Re: Terrain Layers
« on: January 28, 2015, 12:17:39 pm »
I think you are overcomplicating things if you are using chunks with N-layers as vertex arrays.
What if there is tree sprite on the very edge of the chunk? Let's say you are drawing chunks from left to right and your tree is placed to the right border of your first chunk. Now when the second chunk is drawn it will be partially drawn on top of the tree.

In my opinion you should either:

a) Use chunks, but have all the layers stored in separate vertex arrays. The order of drawing would then be:
Left ground chunk>Right ground chunk>Left Scenery chunk>Right scenery chunk etc.
b) Ditch the chunks and use one vertexarray for each layer, draw layers from bottom to top.
c) Ditch the chunks and store all layers in one vertex array.

C would probably be the fastest of these but I'm with Jesper Juhl here. Just go with what feels most logical and easiest to you. Using vertexarrays at all should yield good perfomance already.

Edit:

I prefer option b because:
- It looks good in code and makes sense
- I can use different shader for each layer
- I can use different spritesheet for each layer


43
DotNet / Re: How to use Clock class
« on: January 27, 2015, 02:16:46 pm »
Are the dlls copied into bin directory?

Adding them into project root doesn't automatically copy them.
You'll have to either
a) place them into ProjectRoot/lib and include that folder into the project or
b) use postbuild events to copy them with commandline or
c) copy them manually

44
DotNet / Re: "System.BadImageFormatException" in sfmlnet-graphics-2.dll
« on: December 05, 2014, 06:48:02 pm »
Try changing project's target platform to x86/x64.

45
General / Re: I have a minor issue with passing variables... SOS...
« on: November 24, 2014, 09:58:53 am »
You really need to read some tuts or books about C#. This is pretty basic stuff.

 public class Game
    {
        public Game()
        {
            SomeClass s = new SomeClass();
            s.DoSomething();
            Console.WriteLine(s.Stuff);
        }
    }
    public class SomeClass
    {
        public int Stuff { get; set; }
        public SomeClass() { }

        public void DoSomething()
        {
            Stuff = 123;
        }
    }
Other way around
  public class Game
    {
        public int Stuff { get; set; }
        public Game()
        {
            SomeClass s = new SomeClass(this);
            s.DoSomething();
        }
    }
    public class SomeClass
    {
        private Game _game;
        public SomeClass(Game game)
        {
            _game = game;
        }
        public void DoSomething()
        {
            _game.Stuff = 123;
        }
    }
 
With static class (not recommended)
   
 public static class Game
    {
        public static int Stuff { get; set; }
    }
    public class SomeClass
    {
        public SomeClass() { }
        public void DoSomething()
        {
            Game.Stuff = 123;
        }
    }
With an event:
 
 public class ChangeStuffEventArgs : EventArgs
    {
        public int Stuff { get; set; }
        public ChangeStuffEventArgs() { }
        public ChangeStuffEventArgs(int stuff)
        {
            Stuff = stuff;
        }
    }
    public class Game
    {
        public Game()
        {
            SomeClass s = new SomeClass();
            s.OnStuffChanged += s_OnStuffChanged;
            s.DoSomething();
        }
        void s_OnStuffChanged(object sender, ChangeStuffEventArgs e)
        {
            Console.WriteLine(e.Stuff);
        }
    }
    public class SomeClass
    {
        public event EventHandler<ChangeStuffEventArgs> OnStuffChanged;
        private int _stuff;
        public int Stuff
        {
            get { return _stuff; }
            set
            {
                _stuff = value;

                if (OnStuffChanged != null)
                    OnStuffChanged(this, new ChangeStuffEventArgs(_stuff));
            }
        }

        public SomeClass() { }
        public void DoSomething()
        {
            Stuff = 123;
        }
    }

Choose your weapon.
PS. Making a new thread and new account after first one gets closed is not really a polite thing to do  :)

Pages: 1 2 [3] 4 5
anything