Moscrif API Docs for: 2012q3
Show:

ImageButton Class

include "lib://game2d/imageButton.ms";
Library: game2d

Implements game button functionality. This button can be filled with image. It supports diferent image for normal and pressed state. These two states can be placed in two separate files, or in one file with two frames.

Methods

_drawImage

(
  • canvas
)
private

Draw Image mode, display image based on button state

Parameters:

  • canvas Canvas

    Canvas used to draw sequence

_drawSequence

(
  • canvas
)
private

Method do draw sequence mode, display frame based on button state.

Parameters:

  • canvas Canvas

    Canvas used to draw sequence

aftetInit

() protected

Init button. This method is called from class constructor and it is usually no needed to change it.

draw

(
  • canvas
)
protected

Draw method draws the button.

Parameters:

  • canvas Canvas

    Current game canvas

init

() protected

Init button. This method is called from class constructor and can be used in overwritten classes as a class constructor.

Properties

frame

Integer

Get frame index first frame has index 0 then 1, 2 ...

frameHeight

Integer

Set frame height. Button's image is automatically divided into frames acording to frame width and height.

Example:

var button = new ImageButton ({
    image       : res.img.continueButton,
    x           : System.width/2,
    y           : top,
    frameWidth  : res.img.continueButton.width,
    frameHeight : res.img.continueButton.height / 2,
});

frameWidth

Integer

Set frame width. Button's image is automatically divided into frames acording to frame width and height.

Example:

var button = new ImageButton ({
    image       : res.img.continueButton,
    x           : System.width/2,
    y           : top,
    frameWidth  : res.img.continueButton.width,
    frameHeight : res.img.continueButton.height / 2,
});

image

Bitmap | String

Image on the button. If image contains two frames, first frame is used for normal state and second for pressed state.

Example:

var button = new ImageButton ({
    image       : res.img.continueButton,
    x           : System.width/2,
    y           : top,
    frameWidth  : res.img.continueButton.width,
    frameHeight : res.img.continueButton.height / 2,
});

imagePressed

Bitmap | String

Image on pressed button, displays image when user click on the button. The pressed image can be palced also in one file with normal image.

Example:

var button = new ImageButton ({
    image           : res.img.continueButton,
    imagePressed    : res.img.continueButtonPressed,
    x               : System.width/2,
    y               : top,
});

mode

Symbol

Displaying game button mode: 1. #sequence, this mode calculate based frameWidth or frameHight, segiences and frames Maximum allowed frames for game button is Two 2. #image, game button expect two images. One for normal state second one for pressed state. If pressedImage is not set by default is set to the image

scaledHeight

Integer

Get scaled height of this object

scaledWidth

Integer

Get scaled width of this object

sequence

Array

This property sets sequence of the button frames.

Attributes

instance

ImageButton static

Singleton of the game object.