Discord
Login
Community
DARK THEME

Coloring sprite

Ok, there is the goal:

First goal:
We have 1 sprite (one color & transparent background).
I want to put it twice near each other.
But left one be red, right green.
Second goal:
Make transparent part of this sprites with some other color (like gray for red one and yellow for green).

Make sense:
The color of foreground & background is dynamic, so painting million of same sprites, but with different fore/back color is not an option!

I tried different methods with screen.setBlending (almost any way that can exist i think), but no result (no good one).

See Gilles example (with blue square & red circle), try to use part of code with different [optional] options => no needed result got...

Can anyone help?

I wrote a simple test to see how I could colorize sprites. Maybe this helps, let me know!

https://microstudio.dev/i/gilles/colorize/

Gilles, thanks!

That is just i want :)

And I took @GILLES test and made a mess of it:

https://microstudio.dev/i/Martellus/llfcoldskool/

I created fully animated colorized sprites based on a template sprite.

Well, i get issued...

Try this code as:

char = 17; //Animated sprite frame as character
px = 0; //Player X coordinate
py = 0; //Player Y coordinate

screen.fillRect(0, 0, 8, 8, '#2A6');
buffer = new Image(8, 8, true);
buffer.drawSprite("chars." + char, 0, 0, 8, 8);
buffer.setBlending("source-atop");
buffer.setAlpha(.5);
buffer.fillRect(0, 0, 8, 8, '#62F');
screen.drawImage(buffer, px, py, 8, 8);

And i get error: 'buffer.drawSprite is not a function'

I set project to JS, because in future i need AJAX POST to get/set data in/to my server (user savegames, progress, achivements, hi-scores)...

So... Is there an opinion to AJAX POST in MicroScript in future, or how to beat this error in JS?

UPD:

buffer.setBlending("source-atop");
buffer.setAlpha(.5);
buffer.fillRect(0, 0, 8, 8, '#62F');

All of these throw error too, looks like MicroScript functions does not applied to created objects in JS...

To all:

gilles added JavaScript support into MicroScript projects.

To use it just make this in some source:

//javascript

  ~ some JavaScript only code here ~
First line must be //javascript for this to work!

This allows to use MicroScript with JavaScript source files :3

Thanks, gilles!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community