Possible with monkey to change a sprite color ?

Monkey Forums/Monkey Programming/Possible with monkey to change a sprite color ?

Rushino(Posted 2013) [#1]
Hello,

Just wonder if its possible with current modules or any user modules to change the sprite color teint.

Thanks!


Belimoth(Posted 2013) [#2]
You can use mojo's SetColor which affects the drawing color for a lot of graphics operations, including DrawImage. It is slow to draw tinted images this way on the HTML5 target, but there are ways to work around this: http://monkeycoder.co.nz/Community/posts.php?topic=3276


FelipeA(Posted 2013) [#3]
You could use SetColor, then ReadPixels, write them into a new image and then draw the image. This could help with the slowing down when using SetColor.


Gerry Quinn(Posted 2013) [#4]
ReadImage is maybe the most practical way: when you load the sprite into an array, you can do anything you like to the colour in software.


Whiteball(Posted 2013) [#5]
I've been thinking about this very subject myself recently so any help/code examples here would be very appreciated.

Is SetColor only slow on html5 and ok on all other targets?

What would be the best way to go about having a graphic block of say 8 pixels and wanting to do a color cycling effect which changes the color every 80millisecs or so?

I'm currently using the great diddy framework and want to incorporate some easy way of doing these things instead of having multiple objects all the same shape but different colors in my sprite atlas if possible.


Markus(Posted 2013) [#6]
grey images + set color works if you not have white point of lights.


ElectricBoogaloo(Posted 2013) [#7]
Every target I've tested, other than HTML5, has been fine with SetColor, although I've not tested all the possible targets, yet, I think the only reason HTML5 is slow is simply because HTML5 IS slow! It's a HTML5 issue, not a Monkey one.

For Color Cycling, it mostly depends on how much you want to tweak the color.
Alpha works wonderfully well in HTML5, as does Additive Blend mode (although Additive Blend mode is slow on certain Android devices, so be careful not to overuse that)

Perhaps you could achieve your cycling using two sprites, and a combination of alpha and additive.
Maybe have the sprite in 2 different base colors, then alpha one over the other to make a nice set of mid-tones.
Or if you're after more movement, well then it's probably best to animate a special "html5 target" specific version.

There's always a way around these things, you just have to think within the limits you've got, as opposed to trying to desperately fit the target's limitations into your grand scheme.
..I tend to think of things in terms of 1980's BASIC, and then scale things upwards. Not sure if that helps, but it seems to be flowing well with Monkey!


Whiteball(Posted 2013) [#8]
Thanks all, will try coding up some stuff today with those ideas.


rIKmAN(Posted 2013) [#9]
HTML5 is awful with SetColor, which is a shame as its fastest target to use for testing when compiling and debugging.

The HTML5-GL mod does go some way to improve performance, but even that cannot really overcome the limitations of HTML5 is you are using SetColor a lot.

As per ElectricBoogaloo though, it hasn't caused a problem on any other targets for me yet (iOS/Android/GLFW), its just increased the compile time on my debug builds as I now have to use GLFW.