I want to know the custom shape creation in html5 using LimeJS.Could anyone tell me how to create a custom shape like comment in a game using LimeJS for html5.
for images
var gameMap = new lime.Sprite().setSize(400,300).setFill('images/bk.jpg').setPosition(0,0).setAnchorPoint(0,0);
for custom shapes we have to fill with different points
You essentially create a custom sprite, and render the UI appropriately, which could be a combination of elements. The shell needs to be:
test.board = function() {
goog.base(this);
}
goog.inherits(test.board, lime.Sprite);
Text input isn't direct; here is an article on text input: https://groups.google.com/forum/?fromgroups=#!topic/limejs/txaxgK3eXQg. You can use a label, and attach to the key press event. I don't know if this works for canvas rendering...
Related
I am using the library dragula for doing some drag & drop stuff.
Dragula internally uses cloneNode(true) to create a copy of the dragged element that will be appended to the body to show the preview image while dragging.
Unfortunately, if dragging a polymer element, the bound data get's not cloned. By consequence the contents of the dragged element (e.g. <div>[[someString]]</div>) are empty.
Is there a solution for this?
I actually do not need the data to be bound for my element, it is just a "read-only" element that displays some data that does not change after being initialized. Is there maybe a way to somehow "resolve" the strings to the html without being bound anymore?
Thank you already!
Found a solution myself. You have to override the cloneNode method inside the polymer class:
cloneNode(deep) {
let cloned = super.cloneNode(deep);
for (let prop in MyClass.properties) {
cloned[prop] = this[prop];
}
return cloned;
}
I have a MenuItemImage here:
auto myImage = MenuItemImage::create("image.png","image_selected.png",
CC_CALLBACK_1(HelloWorld::onImageClicked,this));
It allow me to input a image.png, which will be changed to image_selected.png on selected when I navigate between items in my menu with keyboard. However, I want to perform some actions when select it with myImage->selected(); (NOT activate it by clicking/touching or calling for myImage->activate(); function), not just a boring image_selected.png.
Now, I'm thinking about set up all of those action in:
keyBoardListener->onKeyPressed = [&](cocos2d::EventKeyboard::KeyCode keycode, Event* event)
{ // Setting up actions on KEY_RIGHT_ARROW or KEY_LEFT_ARROW pressed};
However this way makes things complicated. Therefore, I want to ask if there's any way that I could set up all of my actions as myImage being creating so I could call all of those action with a simple myImage->selected() or stop them with myImage->unselected() later?
Your attention and help is very much appreciated :D
Simply do this:
auto myImage = MenuItemImage::create("image.png", "image_selected.png", [&](Ref* ref){
//your code here
//by ref you can access "myImage" object
});
edit:
I'm not sure what are you trying to achieve. Do you want to have a few buttons in menu, which always one of the is selected and change them using arrows? (so menu navigation is like on console games).
edit2:
After watch a sample yt video I don't think you can achieve this relying only on MenuItemImage. Instead I'd create a ui::Button (if you need clicking/touching as well) or Sprite. Then I'd handle button states by myself. As for glowing frame you probably need some fancy shader or create it in photoshop and add to it an action with constantly fading out and in.
I am using the KineticJS Sprite object in creation of a simple HTML5 2D canvas game. I need each sprite to have certain characteristics, such as 'shield', 'firepower', 'speed', etc. So I need to add my own custom properties to the Sprite object.
Ideally I want something like:
mySpriteObj.setCustom('shield',50) // set a custom property to 50
...and then later..
var shield = mySpriteObj.getCustom('shield') // returns 50
But there doesn't appear to be anything like that. I did try to use the attr property (getAttr and setAttr) with my own custom values but this did not work.
Is there an easy way to associate your own variables with a Sprite object?
thanks
Owen
Even though getAttr() and setAttr() are the best method to do it, as long as you are not trying to save the canvas using .toJSON() and then recreate the node, you can simply assign whatever custom values directly like this:
mySpriteObj.shield = someValue;
mySpriteObj.speed = someOtherValue;
var myObjSpeed = mySpriteObj.speed;
var myObjShield = mySpriteObj.shield;
Although, you might want to share your code using getAttr() and setAttr() and try to fix error in that.
To add a method to a Kinetic.Shape you can use the addMethods function see the docs
You can check the the Kinetic Source for examples on how to use this method.
Example:
Kinetic.Util.addMethods(Kinetic.Shape, {
getCustom: function() {
//getCustom attribute code here
},
getCustom2: function() {
//getCustom attribute code here
}
});
Notice you can add multiple functions by adding more properties (functions) in the object for the second parameter of the addMethod function.
And like Ani says, you should use the getAttr() and setAttr() functions to get and set the custom attributes.
http://kineticjs.com/docs/Kinetic.Shape.html#getAttr
http://kineticjs.com/docs/Kinetic.Shape.html#setAttr
I'm trying to create a fairly straightforward interface with Raphael, whereby if you click on a given path you'll get a corresponding div to appear. Since I'm likely going to be using irregular shapes I'll be creating the shapes in Illustrator and then converting to paths using readysetraphael.com, but if there's a better way to do it I'm open to that too.
I'm basically looking to capture the functionality you see here, but with raphael objects as the buttons.
http://jsfiddle.net/4xV7b/
Here's my current fiddle -- what I don't understand is what needs to happen during the mouseclick event to show/hide the corresponding divs.
el.click(function() {
//mysterious voodoo magic goes here
});
If you were using Raphael 2, you could use the data method to store arbitrary information with your elements -- as in this example.
Essentially, when you're creating each path, you simply call
el.data( 'div_id', 'greenthing' );
Then, when that element is clicked, you can retrieve the indicated div from the element using
el.click( function()
{
var div_id = this.data( 'div_id' );
// Display the div here. Josemando's approach is perfectly cool and will work universally.
} );
If you wanted to make sure that only one div at a time is displayed, you could do this (primitive but effective):
el.click( function()
{
rsr.forEach( function( subEl )
{
var divId = subEl.data('div_id' );
if ( divId && document.getElementById( divId ) )
document.getElementById( divId ).style.display = 'none';
} );
} );
There are, of course, other ways to skin that cat.
You may also find that your path construction code would be more manageable if you put all of the shape-specific data into a structured object and then render each path in a loop. The fiddle I've provided above demonstrates such a technique, which will pay off quickly once you have more than a handful of shapes.
You can use pure javascript to show a div:
document.getElementById("redthing").style.display = "block";
If you want animations, you can try using jQuery, or even manually creating them with css
Please note the remark mentioned WORKAROUND at the end of this question.
Based on a Dictionary based specification, one of my classes creates a Form programmatically.
Adding TextInput or DatePicker to FormItemss works as expected.
Unfortunately, the following code just creates a colored rectangle, not the actual picker:
ti = new ColorPicker();
ColorPicker( ti ).selectedColor = TAColor( _spec[ key ].value ).color;
and later on
formItem.addElement( ti );
The Form is embedded in a TitleWindow component presented using
PopUpManager.addPopUp(...);
When added to TitleWindow, it shows up correctly, within Form->FormItem not:
I can't image, why the picker doesn't appear. Do you?
WORKAROUND:
If I wrap the ColorPicker inside a Group things work:
ti = new Group();
Group( ti ).addElement( new ColorPicker() );
In this case, the ColorPicker appears as editable.
Still, I'd be too happy to learn what the problem with my initial solution. Bug?
A DateField (which extends ComboBase like ColorPicker) behaves properly in a spark Form. But in the ColorPicker, the mouse down handler of the button never gets called. I think that maybe the skin part that handles the mouse clicks (it must be a button) is not properly dimensionned, and the result is it is not shown. I've come to this conclusion because within an mx Form, the ColorPicker doesn't display as it does when it is added to the regular displaylist...
Hope this helps...
In the code you've provided, you never add the colorPicker as a child to any parent container; as such it will never show up anywhere.
You probably need to do something like:
formItem.addChild(ti );
[or for a Spark formItem]:
formItem.addElement(ti );
I'm confused as to why you're seeing a rectangle.