Skip to main content
Participant
April 18, 2017
Question

CreateJS - Sprite / ButtonHelper button issue(s)?

  • April 18, 2017
  • 0 replies
  • 929 views

Hi again,

I am having an issue with creating buttons in an Animate CC HTML 5 canvas project.  I've tried creating a MovieClip instance in my library, setting a linkage name and creating a frame in the MovieClip for each state, labelled  as "out", "over", "down" and "hit".

Using the ButtonHelper class in CreateJS has "worked", to a degree, producing a functioning button with rollover state, until I try to reposition the button else where on the stage using the .x and .y properties.   When I do this, the hit state seems to "separate" from the rest of the MovieClip - i.e.  to trigger the "rollover" frame,  I would have to mouse over the hit state much further down and to the right of the stage.

My Animate CC trial has now expired, so I am trying to solve my issues with using the CreateJS libraries with plain old fashioned HTML. I have created a spritesheet PNG file with three 50px x 50px images in it, which equals 150px X 50px.  I have created an HTML doc and Javascript code, which follow below, but when the states of the Sprite button do not change when I click "down" on it or mouse "over" it.

I wonder if anything could pass some ideas my way?  There might well be a simple error in what I've written, I'm working by myself and slowing going "code-blind" to it.

Thanks very much,

Dave

-----------

The HTML file I have created is below:

<!DOCTYPE html>

<html lang="en">

  <head>

       <title>Sprite and Spritesheet Testing</title>

       <script type="text/javascript" src="js/easeljs-0.8.2.min.js"></script>

       <script type="text/javascript" src="js/preloadjs-0.6.2.min.js"></script>

       <script type="text/javascript" src="js/soundjs-0.6.2.min.js"></script>

       <script type="text/javascript" src="js/tweenjs-0.6.2.min.js"></script>

       <script type="text/javascript" src="js/custom.js"></script>

       <link type="text/css" rel="stylesheet" href="css/defaults.css" />

  </head>

  <body onload="init();">

       <h1>Using Sprites, SpriteSheets and ButtonHelper</h1>

       <p>Below should be some example Type 26 / Type 45 demonstration buttons.  Hopefully this functionality can be recreated within Animate CC using the CreateJS libraries.</p>

       <!-- CreateJS content will be displayed here -->

       <canvas id="t26Canvas" width="749" height="737" class="setupCanvas">

            <h1>The internet browser you are currently using does not support the &lt;canvas/&gt; HTML 5 element.</h1>

       </canvas>

  </body>

</html>

</html>

My Javascript is below:

/* CUSTOM.JS */

var HTML5Stage;

var spritesheet;

var data;

var myButton;

var myButtonHelper;

function init() {

  // Get the HTML5 <canvas/> element we are going to be using for the CreateJS content.

  HTML5Stage = new createjs.Stage("t26Canvas");

  // Set usable on touch devices

  createjs.Touch.enable(HTML5Stage);

  // Enable capturing of mouse rollover events

  HTML5Stage.enableMouseOver(30);

  setupSpriteSheet();

  addTestButton();

}

function setupSpriteSheet() {

  data = {

        images: ["images/ui/buttonsprites.png"],

        frames: {width: 50, height: 50},

        animations: {

            out: 0,

            over: 1,

            down: 2

        }

    };

  spritesheet = new createjs.SpriteSheet(data);

}

function addTestButton() {

  myButton = new createjs.Sprite(spritesheet);

  myButtonHelper = new createjs.ButtonHelper(myButton);

  HTML5Stage.addChild(myButton).set({x: 300, y: 100})

  HTML5Stage.update();

}

This topic has been closed for replies.