Jump to content

"2D Animated Sprites" Demonstrating a Point


deadlinegrunt
 Share

Recommended Posts

This post, if not deleted by admins or moderators, will serve to demonstrate a point about community, technical support, and feature requests.

Is anybody able to post some code that can demonstrate how to animate a 2D sprite in an equally straight forward manner like creating a window, context, and an entity object that displays on the screen similar to "Hello World" example when first starting out.  You can use a texture atlas or separate images; your choice.  Additionally, for simplification of requirements, Lua or C++ is acceptable.  The primary request is that it should work with the current version of Leadwerks API, 4.5 as of this posting, and not an outdated version where previous features never migrated, it follows a "standardized" format like the help sections in the API which is self contained sans assets, and can be executed.  Not seeking a framework, library, or extensible solution.  Looking for simple and concrete example via code.

This is not a question about theory and discussions "how you could go about it", e.g. use a shader, use a timer, uv texture mapping adjustments on the fly, etc.  Seeking a concrete example that matches the criteria above to demonstrate a point.  If a response is made within 24 hours of this posting and this thread is not drowned out with pointless conversation (prior to said solution meeting criteria set forth) I will donate $50 to the first person to respond with an actual concrete example through convenient digital payment methods that are considered the norm as of this posting.  As an added bonus:  If you can provide a link to an already existing post that matches the criteria above but is not found using the following:  "2d animated sprites" or "2d sprite animation" then I will double the reward to demonstrate the search issues with this site.

*Payment will be received with 24 hours of this bounty being fulfilled.

Link to comment
Share on other sites

Here you go:

#include "Leadwerks.h"

using namespace Leadwerks;

int main(int argc, const char *argv[])
{
	Leadwerks::Window* window = Leadwerks::Window::Create();
	Context* context = Context::Create(window);
        
	//  Load 2 sprite frames
	Texture* texture1 = Texture::Load("Materials/Developer/bluegrid.tex");
	Texture* texture2 = Texture::Load("Materials/Developer/greengrid.tex");

	while(true)
	{
		if(window->Closed() || window->KeyHit(Key::Escape)) break;

		context->SetColor(0.0, 0.0, 1.0);
		context->Clear();
		context->SetColor(1.0, 1.0, 1.0);

		//  Display alternating sprite frames depending on time
		if(Time::Millisecs()%1000>500) context->DrawImage(texture1, 0, 0, 1024, 1024);
		else context->DrawImage(texture2, 0, 0, 1024, 1024);

		context->Sync();
	}
	return 0;
}

 

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...