Constructor
new Costume(options)
constructor - Creates a Costume to be used by Sprite objects..
- Source:
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object
|
options for the costume.
|
Examples
let costume = new blockLike.Costume();
let costume = new blockLike.Costume({
width: 50,
height: 50,
color: '#A2DAFF',
image: 'https://www.blocklike.org/images/sheep_step.png'
});
Extends
Methods
addClass(name)
addClass - adds a css class to costume.
- Overrides:
- Source:
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
the css class name to add. |
Examples
let costume = new blockLike.Costume();
costume.addClass('rainbow');
let backdrop = new blockLike.Backdrop();
backdrop.addClass('rainbow');
addTo(sprite)
addTo - Adds the costume to the sprite
- Source:
Parameters:
Name | Type | Description |
---|---|---|
sprite |
object
|
which sprite to add the costume too. |
Example
let sprite = new blockLike.Sprite();
let costume = new blockLike.Costume();
costume.addTo(sprite);
css(prop, value)
css - applies a CSS rule to a Costume or Backdrop.
- Overrides:
- Source:
Parameters:
Name | Type | Default | Description |
---|---|---|---|
prop |
string
|
the css property (e.g. color) | |
value |
string
|
null | the value for the css property (e.g. #ff8833) |
Examples
let costume = new blockLike.Costume();
costume.css('font-size', '16px');
let backdrop = new blockLike.Backdrop();
backdrop.css('cursor', 'pointer');
hasClass(name) → {boolean}
hasClass - is the css class applied to the costume.
- Overrides:
- Source:
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
the css class name. |
Returns:
- Type:
-
boolean
- is the css class name on the list.
Examples
let costume = new blockLike.Costume();
costume.hasClass('rainbow') ? costume.removeClass('rainbow') : costume.addClass('rainbow');
let backdrop = new blockLike.Backdrop();
backdrop.hasClass('rainbow') ? backdrop.removeClass('rainbow') : backdrop.addClass('rainbow');
inner(html)
inner - Places an HTML element inside the costume.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
html |
string
|
the html to insert. |
Examples
let costume = new blockLike.Costume();
costume.inner('<p class="big centered rainbow">:)</p>');
costume.inner('I like text only');
insert(el)
insert - Places a DOM element inside the costume.
- Source:
Parameters:
Name | Type | Description |
---|---|---|
el |
object
|
the DOM element. |
Example
let costume = new blockLike.Costume();
costume.insert(document.getElementById('my-html-creation'));
removeClass(name)
removeClass - removes a css class from the costume.
- Overrides:
- Source:
Parameters:
Name | Type | Description |
---|---|---|
name |
string
|
the css class name to remove. |
Examples
let costume = new blockLike.Costume();
costume.hasClass('rainbow') ? costume.removeClass('rainbow') : costume.addClass('rainbow');
let backdrop = new blockLike.Backdrop();
backdrop.hasClass('rainbow') ? backdrop.removeClass('rainbow') : backdrop.addClass('rainbow');
removeFrom(sprite)
removeFrom - Removes the costume from to the sprite
- Source:
Parameters:
Name | Type | Description |
---|---|---|
sprite |
object
|
which sprite to remove the costume from. |
Example
let sprite = new blockLike.Sprite();
let costume = new blockLike.Costume();
costume.addTo(sprite);
costume.removeFrom(sprite);
resizeToImage()
resizeToImage - sets the width and height of the costume to that of the image file.
- Source:
Example
let costume = new blockLike.Costume({
image: 'https://upload.wikimedia.org/wikipedia/commons/d/d3/Sheep_in_gray.svg'
});
costume.resizeToImage();