Skip to content
This repository has been archived by the owner on Jun 11, 2022. It is now read-only.
This repository has been archived by the owner on Jun 11, 2022. It is now read-only.

Iterating over SpriteSheet starts at index 1 and ends at index 0 #55

Closed
apahl opened this issue Sep 6, 2015 · 13 comments
Closed

Iterating over SpriteSheet starts at index 1 and ends at index 0 #55

apahl opened this issue Sep 6, 2015 · 13 comments

Comments

@apahl
Copy link

apahl commented Sep 6, 2015

Hi, thanks for providing this excellent game library for D.
It seems to me, that iterating over a SpriteSheet using slideTextureRect() as described in the tutorial for the explosion starts with the rectangle at index 1 and ends with index 0. This can be seen when using a large timeout explosion.timeout = 1000; and explosion.numOfExecutions = 1; .
Kind regards,
Axel

@Dgame
Copy link
Owner

Dgame commented Sep 6, 2015

As soon as you call slideTextureRect the texture rect is updated, that is correct. At the end it is set back to 0 so that a new call to slideTextureRect has the same effect as before. Or did I missunderstand you? Maybe it would be easier if you can provide your code and describe in which form it affects your work.

@apahl
Copy link
Author

apahl commented Sep 7, 2015

Thanks for coming back so quickly.
What I meant is that playing through the SpriteSheet using slideTextureRect() appears to never start at the first frame with index 0, but always with the second frame at index 1, then loops over the rest of the frames and ends with the first frame at index 0 (when numOfExecutions = 1is used).
This can be seen in this slowed down example from the tutorial:

import std.stdio;

import Dgame.Window.Window;
import Dgame.Window.Event;
import Dgame.Graphic;
import Dgame.Math.Rect;
import Dgame.System.StopWatch;

void main() {
    Window wnd = Window(640, 480, "Dgame Test");
    wnd.setVerticalSync(Window.VerticalSync.Enable);
    wnd.setClearColor(Color4b.Black);

    Surface explo_img = Surface("images/explosion.png");
    Texture explo_tex = Texture(explo_img);

    Spritesheet explosion = new Spritesheet(explo_tex, Rect(0, 0, 256, 256));
    explosion.numOfExecutions = 1;
    explosion.timeout = 500;

    bool running = true;

    wnd.clear();
    wnd.display();
    StopWatch.wait(2000);

    Event event;
    while (running) {
        wnd.clear();

        while (wnd.poll(&event)) {
            switch (event.type) {
                case Event.Type.Quit:
                    writeln("Quit Event");

                    running = false;
                    break;

                default: break;
            }
        }

        wnd.draw(explosion);
        explosion.slideTextureRect();

        wnd.display();
    }
}

Kind regards,
Axel

@Dgame
Copy link
Owner

Dgame commented Sep 7, 2015

Thanks for the snippet. I'll investigate that tonight.

@Dgame Dgame closed this as completed in 132252e Sep 8, 2015
@Dgame
Copy link
Owner

Dgame commented Sep 8, 2015

@apahl Should be fixed. Would you please test the change?

@apahl
Copy link
Author

apahl commented Sep 8, 2015

I'm sorry, but that has not changed the behaviour for me.

@Dgame
Copy link
Owner

Dgame commented Sep 8, 2015

That is strange. I've tested your code twice and got the same output and at very last I see the first frame.
Here is my output (I put printf's before and after each if inside of the method)
First run:

next column (256:0)
next column (512:0)
next column (768:0)
next column (1024:0)
next column (1280:0)
next column (1536:0)
next column (1792:0)
next column (2048:0)
next row (0:256)
next column (256:256)
next column (512:256)
next column (768:256)
next column (1024:256)
next column (1280:256)
next column (1536:256)
next column (1792:256)
next column (2048:256)
next row (0:512)
next column (256:512)
next column (512:512)
next column (768:512)
next column (1024:512)
next column (1280:512)
next column (1536:512)
next column (1792:512)
next column (2048:512)
next row (0:768)
next column (256:768)
next column (512:768)
next column (768:768)
next column (1024:768)
next column (1280:768)
next column (1536:768)
next column (1792:768)
next column (2048:768)
next row (0:1024)
next column (256:1024)
next column (512:1024)
next column (768:1024)
next column (1024:1024)
next column (1280:1024)
next column (1536:1024)
next column (1792:1024)
next column (2048:1024)
next row (0:1280)
next column (256:1280)
next column (512:1280)
next column (768:1280)
next column (1024:1280)
next column (1280:1280)
next column (1536:1280)
next column (1792:1280)
next column (2048:1280)
next row (0:1536)
        end (0:1536)

and second run:

next column (256:0)
next column (512:0)
next column (768:0)
next column (1024:0)
next column (1280:0)
next column (1536:0)
next column (1792:0)
next column (2048:0)
next row (0:256)
next column (256:256)
next column (512:256)
next column (768:256)
next column (1024:256)
next column (1280:256)
next column (1536:256)
next column (1792:256)
next column (2048:256)
next row (0:512)
next column (256:512)
next column (512:512)
next column (768:512)
next column (1024:512)
next column (1280:512)
next column (1536:512)
next column (1792:512)
next column (2048:512)
next row (0:768)
next column (256:768)
next column (512:768)
next column (768:768)
next column (1024:768)
next column (1280:768)
next column (1536:768)
next column (1792:768)
next column (2048:768)
next row (0:1024)
next column (256:1024)
next column (512:1024)
next column (768:1024)
next column (1024:1024)
next column (1280:1024)
next column (1536:1024)
next column (1792:1024)
next column (2048:1024)
next row (0:1280)
next column (256:1280)
next column (512:1280)
next column (768:1280)
next column (1024:1280)
next column (1280:1280)
next column (1536:1280)
next column (1792:1280)
next column (2048:1280)
next row (0:1536)
        end (0:1536)

They are identical and prove that at the end of the run the first frame is shown (and not the second one as before).

@Dgame Dgame reopened this Sep 8, 2015
@Dgame
Copy link
Owner

Dgame commented Sep 8, 2015

Just out of interest: What did you expect at the end of the run? The first frame or nothing, since the execution went through? Because the former should be and (as far as I can tell) is the case.

@apahl
Copy link
Author

apahl commented Sep 8, 2015

I thought that at the end of the run the last frame would be displayed, which, in case of the explosion, is an empty image.

@Dgame
Copy link
Owner

Dgame commented Sep 8, 2015

We're getting closer. :) I could implement it that way, but currently the behaviour is expected, because mostly you want a running or moving animation with a continuous cycle. That is why the first frame is shown after a cycle is complete. But I think your behaviour and the current shouldn't exclude each other. I'll try to make it adjustable for both behaviours.

@apahl
Copy link
Author

apahl commented Sep 8, 2015

Great! Thanks a lot for your efforts!

@Dgame Dgame closed this as completed in 15cceab Sep 8, 2015
@Dgame
Copy link
Owner

Dgame commented Sep 8, 2015

@apahl Could you test again?

@apahl
Copy link
Author

apahl commented Sep 8, 2015

Works perfectly now! Thanks a lot!!

@Dgame
Copy link
Owner

Dgame commented Sep 8, 2015

My pleasure. ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants