MCPcopy Create free account
hub / github.com/LibreSprite/LibreSprite / createBasicSprite

Method createBasicSprite

src/doc/sprite.cpp:89–118  ·  view source on GitHub ↗

static

Source from the content-addressed store, hash-verified

87
88// static
89Sprite* Sprite::createBasicSprite(doc::PixelFormat format, int width, int height, int ncolors)
90{
91 // Create the sprite.
92 std::unique_ptr<doc::Sprite> sprite(new doc::Sprite(format, width, height, ncolors));
93 sprite->setTotalFrames(doc::frame_t(1));
94
95 // Create the main image.
96 doc::ImageRef image(doc::Image::create(format, width, height));
97 doc::clear_image(image.get(), 0);
98
99 // Create the first transparent layer.
100 {
101 std::unique_ptr<doc::LayerImage> layer(new doc::LayerImage(sprite.get()));
102 layer->setName("Layer 1");
103
104 // Create the cel.
105 {
106 auto cel = std::make_shared<doc::Cel>(doc::frame_t(0), image);
107 cel->setPosition(0, 0);
108
109 // Add the cel in the layer.
110 layer->addCel(cel);
111 }
112
113 // Add the layer in the sprite.
114 sprite->folder()->addLayer(layer.release()); // Release the layer because it's owned by the sprite
115 }
116
117 return sprite.release();
118}
119
120//////////////////////////////////////////////////////////////////////
121// Main properties

Callers

nothing calls this directly

Calls 9

clear_imageFunction · 0.85
folderMethod · 0.80
setTotalFramesMethod · 0.45
getMethod · 0.45
setNameMethod · 0.45
setPositionMethod · 0.45
addCelMethod · 0.45
addLayerMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected