Costume

Costume

Class representing a Costume. Costumes can be added to a Sprite.

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.
Name Type Description
width number the costume width in pixels. Default is 100.
height number the costume height in pixels. Default is 100.
image string a URI (or data URI) for the costume image.
color string a css color string ('#ff0000', 'red')
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.
Inherited From:
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.
Inherited From:
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.
Inherited From:
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 - inserts html into 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 sprite.
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.
Inherited From:
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();