My first post - please bear with me: I’m a writer, not a coder (yet!) I’ve read documentation forums for Hype, jQuery, JavaScript, looked at about 10 other Hype projects, and checked 7 books on JavaScript/jquery - and can’t find answers. If there’s some reference I’m missing, could you please direct me to it? I’ve probably spent 20 hours searching for answers …
Background: I’ve written my first coded hype project, aimed at both an iBook widget and web use;
- I added jquery ui and touch punch to my file (the widget with touch punch works in an IBA book on iPad but crashes iBooks for Yosemite - not my main concern, but any advice would be appreciated);
-
I created 6 draggable images (jpgs) using
$("#angry").draggable({ revert: “invalid”, zIndex: 1 });
-
I created 6 droppable rectangles using Hype’s drawing tool and
$("#boxAngry").droppable({ accept: "#angry", zIndex: 2, drop: function() { hypeDocument.playTimelineNamed("angry"); } });
[In the timeline, the droppable rectangle changes color and the border grows]. This all works as designed. Each droppable signals success.
Problem: Now I want to let the player know that the game is over and s/he’s won by shifting to another scene. To know when to trigger this, it is necessary to determine if all of the draggables have reached their droppable. I can imagine several ways to do this:
-
I assume there’s some way to check if the drop has occurred for each droppable;
-
I imagine that it’s possible to check for one of the changes implemented by the drop: function() timeline being completed in all cases.
I decided to try the second, but immediately ran into a problem. The color of the main body of the rectangle is called “fill style” in Hype, but background is called “background-color” in CSS - so first big question: how do I know how to refer to various properties of elements when using Hype?
I tried wording like:
if("boxAfraid").fillStyle == "#efa17b" && ...){
hypeDocument.showSceneNamed(Win);
}
and a similar construction using
if("boxAfraid").style.background-color == ...
but neither works. Question 2: How is this properly done (or should I be checking for completion in some other way?)?
Question 3: When the code - whatever it is - is added, where does it go? Is it part of
function dragAndDrop(hypeDocument, element, event) (
or
$(document).ready(function(){
or is it something new?
Question 4: If there’s something else I haven’t asked about properly setting up a multiple drag/drop game with a change to the droppable in each case and a final scene change to indicate winning, could you please let me know what I’ve failed to take into account?
Question 5: I’d like to get the draggable to snap to the appropriate droppable, but the documentation for snap suggests that draggables can only snap to other draggables (e.g., for a puzzle), but in general, the documentation for jQuery UI is so curt that I have trouble interpreting it, so I may have misunderstood. Any advice, would be most welcome.
Thanks very much.