Is it possible to give move effect on a UITextField.
var aminolabel:UITextField;
var aminoLabelMove:Move = new Move(aminolabel);
aminoLabelMove.xFrom = 0;
aminoLabelMove.xTo = 100
aminoLabelMove.duration = 1300;
aminoLabelMove.play();
UITextField could not have animations like move. Which internally calls transformX, transformY. Can have Face effect animation.
Solution
Add UITextField instance to a UIComponent and apply the move effect to the UIComponent.
Example
var aminolabel:UITextField;
var aminoLabelUI:UIComponent;
aminoLabelUI.addChild(aminolabel);
var aminoLabelMove:Move = new Move(aminoLabelUI);
aminoLabelMove.xFrom = 0;
aminoLabelMove.xTo = 100
aminoLabelMove.duration = 1300;
aminoLabelMove.play();
Related
var mainStack = new UIStackView();
mainStack.Alignment = UIStackViewAlignment.Leading;
mainStack.Spacing = 10;
mainStack.Axis = UILayoutConstraintAxis.Vertical;
mainStack.Frame = new CGRect(10,10,Frame.Width - 30,Frame.Height - 100);
var mainStack1 = new UIStackView();
mainStack1.Alignment = UIStackViewAlignment.Center;
mainStack1.Spacing = 10;
mainStack1.Axis = UILayoutConstraintAxis.Vertical;
mainStack1.Frame = new CGRect(5, 5, Frame.Width - 30, Frame.Height - 200);
this.AddSubview(mainStack);
this.AddSubview(mainStack1);
These are the two subviews i have used, I want to insert one subview below to another subview. I faced a problem that the two subviews are override.
The easiest thing is to change the order you add the views. The last one added will be on top, so if the issue is just with the exact code you shared, just reverse the order of adding the subviews:
this.AddSubview(mainStack1);
this.AddSubview(mainStack);
Also you can bring a subview to the front with (assuming this is a view):
this.BringSubviewToFront(mainStack);
Or you can adjust the Z-Order using the Layer property of a view:
mainStack1.Layer.ZPosition = 0;
mainStack.Layer.ZPosition = 1;
UIView.Layer with higher z positions will appear in front of UIView.Layer with lower z positions.
i am new in cocos2d-js here, i just created this code:`
var that = this;
that._dice
// add player
// create sprite sheet
cc.spriteFrameCache.addSpriteFrames(res.dice_plist);
var spriteSheet = new cc.SpriteBatchNode(res.diceRed_png);
that.addChild(spriteSheet, 2);
// init runningAction
var animFrames = [];
for (var i = 1; i < 7; i++) {
var str = "dieRed" + i + ".png";
var frame = cc.spriteFrameCache.getSpriteFrame(str);
animFrames.push(frame);
}
var animation = new cc.Animation(animFrames, 0.1);
that.runningAction = new cc.Repeat.create(new cc.Animate(animation), Math.random()*10);
var diceSprite = new cc.Sprite("#dieRed1.png");
diceSprite.visible = true;
console.log(this.getContentSize(diceSprite));
diceSprite.runAction(this.runningAction);
that._dice.push(diceSprite);
var size = cc.winSize;
spriteSheet.setPosition(size.width/6.5, size.height/1.20);
spriteSheet.setAnchorPoint(0.5, 0.5);
spriteSheet.addChild(diceSprite, 2);
`
and i would like to use the getFrames() feature to return the array of ccanimation frames. i'm just thinking to get the information of which picture are being animated on the screen there, for example, if the #dieRed1.png is being animated or visible on the screen, it would show value or return value of 1. i have tried to googled around and cannot find any other clue there. if there is any better method, i would love to see that as well. sorry for the english anyway, a bit confused how to arrange the words. thank you :)
Ok, so refering to
the official docs
{Array} getFrames()
Returns the array of animation frames
Which means you can just do:
var frames = animation.getFrames();
To get the array. And then you'll receive an array of cc.AnimationFrame.
To get sprite link do:
var frame = frames[0];//cc.AnimationFrame
var spriteFrame = frame.getSpriteFrame(); //cc.SpriteFrame
var texture = spriteFrame.getTexture(); // cc.Texture
And the texture itself should have the name attribute which may do the job.
I have a moveTo sprite action and I am trying to have the sprite animate while moving. It is a waling animation.
My trouble is I can make the sprite moveTo or animate but not both together so that when the sprite stops moving the animation goes back to the standing frame.
I am using cocos2d-js v3.0
this.sprite = new cc.Sprite.create("#player-stand-f-0");
this.sprite.setPosition(new cc.Point(300,300));
this.addChild(this.sprite);
var animFrames = [];
var str = "";
for (var i = 0; i < 5; i++) {
str = "player-walk-f-" + i;
var spriteFrame = cc.spriteFrameCache.getSpriteFrame(str);
var animFrame = new cc.AnimationFrame();
animFrame.initWithSpriteFrame(spriteFrame, 1, null);
animFrames.push(spriteFrame);
}
var animation = cc.Animation.create(animFrames, 0.025);
var animate = cc.animate(animation);
sprite_action = cc.MoveTo.create(2,cc.p(x,y));
this.sprite.runAction(sprite_action);
this.sprite.runAction(animate);
I have also tried the following but the walking would animate once and not continue until moveTo stops.
var seq = cc.sequence(animate, sprite_action);
If you use "cc.sequence" action it will animate first then move. But if you want to animate the sprite sheet while moving it, there are two ways to achieve that:Look into "cc.Spawn" action. It is used for the purpose just like you need. Another convenient method is to run two actions concurrently.. Below mentioned code will give you the idea.
// create sprite sheet
cc.SpriteFrameCache.getInstance().addSpriteFrames(spritesheet_plist); // add Spritesheet Plist
var SpriteSheet = cc.SpriteBatchNode.create(spritesheet_png); // add Spritesheet Png
this.addChild(SpriteSheet,1);
// Push the frames for animation
var animFrames = [];
for (var i = 0; i < 6; i++) {
var str = "sequence_" + i + ".png";
var frame = cc.SpriteFrameCache.getInstance().getSpriteFrame(str);
animFrames.push(frame);
}
// taadaa ...!! Animate the sprites
var animation = cc.Animation.create(animFrames, 0.06);
var sprite = cc.Sprite.createWithSpriteFrameName("sequence_0.png");
sprite.setAnchorPoint(0.5,0.5); // optional
sprite.setScale(1.0,1.0); // optional
sprite.setPosition(widhthPostion, heightPosition);
sprite.runAction(cc.RepeatForever.create(cc.Animate.create(animation)));
SpriteSheet.addChild(sprite,1);
// Move the sprite
var actionMove = cc.MoveTo.create(duration, cc.p(destinationX, destinationY));
sprite.runAction(actionMove);
In order to manage automatic scrolling in a content editable UIWebView, I need to get the correct caret Y vertical coordinate.
I identified two methods, using javascript.
The first one uses getClientRects javascript function:
CGRect caretRect = [self.webView stringByEvaluatingJavaScriptFromString: #"
var sel = document.getSelection();
var range = sel.getRangeAt(0).cloneRange();
range.collapse(true);
var r =range.getClientRects()[0];
return '{{'+r.left+','+r.top+'},{'+r.width+','+r.height+'}}';"];
int caretY = caretRect.origin.y;
With this, the caret keeps blinking and one gets its correct vertical position with one problem: when user type return key, so that the next line is empty, caretY is equal to zero until a character key is typed. So that this method cannot be use.
The second one insert a tmp span, then removes it:
int caretY = [[self.webView stringByEvaluatingJavaScriptFromString: #"
var sel = window.getSelection();
sel.collapseToStart();
var range = sel.getRangeAt(0);
var span = document.createElement(\"span\");
range.insertNode(span);
var topPosition = span.offsetTop;
span.parentNode.removeChild(span);
topPosition;"] intValue];
This gives the correct caretY in any situation. But the caret stops blinking, which is very unhelpful to see it on the screen.
Does anybody knows any method (or adaptation of these) that can make the following:
- get the correct caret Y in any situation
- keep the caret blinking in any situation
Thanks
Not sure if this is too late; the following works for me.
Add getCaretY() below to your js file:
function getCaretY() {
var y = 0;
var sel = window.getSelection();
if (sel.rangeCount) {
var range = sel.getRangeAt(0);
if (range.getClientRects) {
var rects = range.getClientRects();
if (rects.length > 0) {
y = rects[0].top;
}
}
}
return y;
}
Then call it from obj-c file as below:
NSString *yPos = [webView stringByEvaluatingJavaScriptFromString:#"getCaretY()"];
Open this JS Fiddle Link. There are two paths which are animating. the dark blue bar animates according to minutes passed & the smaller green bar animates according to seconds. I want to loop this animations when they complete their animation. How can I do that?
JS Fiddle Link
window.onload= function aa () {
var paper = Raphael(0, 0, 1900, 1900);
var date = new Date;
var hour = date.getHours();
var mins = date.getMinutes();
var secs = date.getSeconds();
var secl = (60*60*1000)-(secs*1000);
var minl = 60 - mins;
var crx = 318*(mins/60);//sets width according to minutes passed when window is loaded
var cry = 318*(secs/60);//sets width according to seconds passed when window is loaded
var sec1 = (60-secs)*1000;
var x=1;
var y=1;
var pathhh = "M"+x+","+y+" "+"h"+320+" "+"v"+270+" "+"h"+(-320)+"z";//bg
var curbox = paper.path(pathhh).attr({fill:'315-#0299fa-#0473ba'});
var pathh3 = "M"+(x+1)+","+(242+y)+" "+"h"+318+" "+"v"+27+" "+"h"+(-318)+"z";//black bar
var cur1box = paper.path(pathh3).attr({fill:'black'});
var pathfm = "M"+(x+1)+","+(243+y)+" "+"h"+crx+" "+"v"+20+" "+"h"+"-"+crx+"z";//minutes bar
var pathto = "M"+(x+1)+","+(243+y)+" "+"h"+318+" "+"v"+20+" "+"h"+(-318)+"z";
var cu2box = paper.path(pathfm).attr({fill:'#03558b',stroke:'none'});
cu2box.animate({path: pathto},secl);
var patgfm = "M"+(x+1)+","+(265+y)+" "+"h"+cry+" "+"v"+4+" "+"h"+"-"+cry+"z"; //seconds bar
var patgto = "M"+(x+1)+","+(265+y)+" "+"h"+318+" "+"v"+4+" "+"h"+(-318)+"z";
var cu3box = paper.path(patgfm).attr({fill:'#0db1af',stroke:'none'});
cu3box.animate({path: patgto},sec1);
};
I think this question is relevant, while not quite the same as yours. The question and the answer together contain the solution for your case: use the callback at the end of the animation, reset the path to the original and set the new animation.
Alternatively, use setInterval to reset the animation every minute/hour.