Sprite Sheet Sprite Addition - sprite

So i have this spritesheet here:
And as seen on the left, you have to “add” the individual sprite parts, how do i do this?

I imagine there's a dedicated color (looks like pink) that should be treated not as a color but as transparency. So, you draw the first one without drawing any pixels that are pink (that is, leaving the background as is), then you draw the second one on top of it in a similar fashion, then the third and so on.

Related

How to detect that a sprite has encountered a color in pygame

I want to detect that the sprite has encountered a color in pygame, which function should I use to achieve this function.
Though it is possible to get the color at any point in the surface that you want to check against using get_at() (docs here). You would need to find the new area that your sprite covered that it did not cover last time and check every pixel in that, and if other things were moving around you would have to check if your sprite now overlapped with any of those area and check that. Or you could decide that was too complicated and just run through every pixel under your sprites location (without you sprite drawn yet) and check for that color.
It is possible, but would likely not be very fast.
An alternative is if you know where those colors are you can mark those areas using rects, circles, sprites or masks (see here and here) that you can check against. That is usually much faster. These do not have to be drawn and so would be invisible. They would just be used to mark areas for the collision check.
If you do not know exactly where the colors are in the background or the other images, you can create masks based on the colors in them using pygame.mask.from_surface() or pygame.mask.from_threshold() (docs here and here).

Change tint on a sprite with phaser

I have a sprite representing a character in Phaser 2.3.0.
I want to change all the red tint in this sprite by another tint keeping the same luminosity.
I don't want to change other color than red, so the tint property doesn't help me.
Is there an easy way to do something like that?
No there's no "easy" way to do this really. The tint effect is additive across the whole image, not one colour channel.
You could draw the image to a BitmapData and then use its ability to process pixels (or replace colours) to create the effect you want. But if you're doing this a lot (i.e. with lots of different objects, or animated sprites, or large images, or lots of different colours), or in hot areas of your code then it's not a great idea. It uses extra memory and more importantly processing time as each pixel is recoloured.
If you only ever need one fixed tint colour, and you don't need to apply it to lots of sprites, then personally the fastest way (from a rendering perspective) is to have red tinted sprites in your sprite sheets. Uses more memory and load time, but decreases processing time to nothing.
Depending entirely on your type of game you should know for yourself which option sounds best, as it's not a "one hat fits all" problem.

libgdx - how to change the color of a pixel in a TiledMapTile?

I succeeded in retrieving the exact tile my player is on, at runtime when walking around the tiledmap. I'd like now to add some alpha marks on the terrain when passing over, and to do that I need to modify the color of some pixels of the tile.
I really don't know how to do it right now.. any hints?
thanks.
You probably want to draw decorations on top of the tiles, rather than modifying the tiles themselves. The tile images are shared across all cells using a tile, so if you modify the tile itself you would see the change everywhere it was used. Further, modifying the texture is a relatively expensive operation that you probably should try to avoid.
To draw on top the tiles, you might draw additional sprites, or use a custom shader.

How to implement an eraser tool in a simple drawing app?

I have a prototype of a simple drawing application. When the user drags a finger across the screen, I record the points along the way and draw a series of lines between them. In other words, a drawing is a list of “paths” and each path is a list of points to connect. This is easy, it works and it’s efficient.
The problem is I’d like to implement an eraser tool. In a regular bitmap editor the eraser simply erases pixels, but in my drawing there are no pixels to erase – all pixels are created dynamically by stroking the paths. I could do a simple eraser by “drawing” using the background colour, overlaying the already painted paths. But I’d like to draw on a textured background, so that’s a no-go.
How would you do this? (Short of the obvious solution of representing the drawing as a bitmap where the eraser is simple.)
You can't implement an eraser in the traditional sense; what you describe with recording the paths and drawing them dynamically is vector graphics. The concept of an eraser comes from raster graphics (a bitmap, basically). With vector graphics, the user generally selects an item or an area of items to delete.
If you really wanted to do this, you'd basically have to do collision detection between all of the paths in your graphic and the rectangle (or whatever shape) of the eraser. When contact occurs, you'd have to cut the colliding graphic object on either side of the eraser by using the slope of the line(s) in contact with the eraser and the point of intersection.
You could probably find the intersections of your existing paths and the deleted area, split the existing paths up, and create new points at the intersections (which would become start/end points of the newly split paths).
I could do a simple eraser by
“drawing” using the background colour,
overlaying the already painted paths.
But I’d like to draw on a textured
background, so that’s a no-go.
Can't you do an "eraser by drawing" except you don't use a single color but the whole background as color. I mean, for a given path to erase, you take one by one each pixel and color it with the background color of the same pixel cordinates

MFC: Drawing lines of different colors

I have two series of N points I want to graph in two different colors. I can't find anything that explicitly states the best way to go about this simple task when using MFC CDC and CPen objects, and as bunch of CDC::MoveTo/CDC::LineTo calls.
It seems each device context can only have one pen object selected at a time, so am I best to select a pen, draw one line, select another pen, draw the other line... or run through my data once, somehow swapping between pens at each point (either continually selecting each pen, or changing the pen color somehow).
I think your best bet would be to do as you said and draw the first series of N points with the first pen, then select the second pen and draw the second series of N points.
There's no way to change a pen color once you've created it. However you did miss one option, which is to draw all segments of a given color with a pen of that color, then switch pens and draw all segments of the other color. That option may not deliver identical results as the overlap of two segments will depend on which is drawn first.
As unpleasant as it may seem, I think your best option is to switch pens for each new color and go through the points in order.

Resources