Download

Paper2D Flipbook Index

I know I must be just glancing over this, but I have looked a few times.

I know how to set and get the flipbook sprite, but I have no idea how to return its current image index. Game Maker (as a poor example) has an image_index. I see things like GetSpriteAtFrame, but that is not working. I need to know the current frame of animation the sprite is on at the time of checking.

Thanks for any help.

Sprite->?

Is the answer here somewhere?

Edit: I also need to be able to set the frame, or the image_index.

It would also help to know if the framerate can be set programatically or if setting it on the individual flipbook is the only way. I see a way to GetFlipbookFramerate, but no set.

Edit 2: So we solved the issue on how to get and set the image_index. I am sharing and asking that this be included with Paper2D, as setting the scrubber is not ideal for fighting games.


int32 ATestPlatformOriginalCharacter::get_image_index() {
	return Sprite->GetFlipbook()->GetKeyFrameIndexAtTime(Sprite->GetPlaybackPosition());
}

void ATestPlatformOriginalCharacter::set_image_index(int32 frame) {
	//Get number of frames.
	float framecount = Sprite->GetFlipbookLengthInFrames();
	float gettimeposition = (frame + 1) / framecount;

	if (gettimeposition > 1) {
		Sprite->SetPlaybackPosition(1.0f, false);
	} else {
		Sprite->SetPlaybackPosition(gettimeposition, false);
	}
	
}

Getting the first couple of returns was easy, but I am still stuck. I have a feeling since Paper2D is so new, I might need one of the developers to help here. The last three on this list are still stumping me. I know there is a get sprite by index, but the index is exactly what we are trying to return. Without this number, our current development is frozen.

Thanks for any help or tips in the right direction.



//Get image_number of active animtion: Sprite->GetFlipbookLengthInFrames() INT
//Get image_number of active animtion method 2: Sprite->GetFlipbook()->GetNumFrames() INT
//Get image_number of specified animation: RunningAnimation->GetNumFrames() INT
//Get frame rate of active animation: Sprite->GetFlipbookFramerate() FLOAT
//Set frame rate of active animation: ?
//Get image_index of current animation: ?
//Set image_index of current animation: ?

Note: image_index is the current frame number the active animation is on, we need to be able to both get and set this.

Ok ladies and gents, here is how you get the current frame you are on:


Sprite->GetFlipbook()->GetKeyFrameIndexAtTime(Sprite->GetPlaybackPosition()))

I will be back later with how to set it.

Alright everyone, here is the answer on how to both get and set the image_index.
The image_index is the frame number.
I would request that this is included in the core of Unreal 4 and Paper2D.


int32 ATestPlatformOriginalCharacter::get_image_index() {
	return Sprite->GetFlipbook()->GetKeyFrameIndexAtTime(Sprite->GetPlaybackPosition());
}

void ATestPlatformOriginalCharacter::set_image_index(int32 frame) {
	//Get number of frames.
	float framecount = Sprite->GetFlipbookLengthInFrames();
	float gettimeposition = (frame + 1) / framecount;

	if (gettimeposition > 1) {
		Sprite->SetPlaybackPosition(1.0f, false);
	} else {
		Sprite->SetPlaybackPosition(gettimeposition, false);
	}
	
}