Hoping someone can help me with this... I'm following examples seen here for CCMenuAdvanced but am ending up with a weird result, I see my menu and it scrolls but using the boundaryRect property I can't seem to get it to hide part of the menu and show what I want.
Here's my code:
// Setup Menu Alignment
[menuA alignItemsVerticallyWithPadding:0 bottomToTop:NO]; //< also sets contentSize and keyBindings on Mac
menuA.isRelativeAnchorPoint = YES;
menuA.boundaryRect = CGRectMake(0, 100, 230, 200);
[menuA fixPosition];
[self addChild:menuA];
I'm able to scroll and view my entire list which is good, but I can't set up an area to view only part of the menu at a time, which is what boundaryRect should do. Has anyone used this before and can give me some advice?!?
Thanks!
Well, not from the same class, but a home grown scrolling menu. I use the visibility and transparencies of the menuItems themselves. When scrolling up, if a menu label approaches the rectangle's edge, i start fading it out to 0. When the anchor point of the menuItem is outside the rectangle, i set its visibility to NO (thus cant be clicked). Same going down. Clamping is tricky. You have to set these properties when the list of menuItems changes, in case it grows shorter than the height of the boundary rectangle, or grows again greater than the rectangle. Something like this (edited, not actual code ... dont know if it compiles :) ):
-(void) fixMenuItemOpacity:(CCMenuItemLabel*) mi{
float theY = mi.position.y ;
if (fadeOutZoneHeight_<4.0f) {
if (theY> self.boundaryRect.origin.y+self.boundaryRect.size.height/2 - fadeOutZoneHeight_) {
mi.visible=NO;
} else if( theY < self.boundaryRect.origin.y-self.boundaryRect.size.height/2 + fadeOutZoneHeight_) {
mi.visible=NO;
} else {
mi.visible=YES;
}
return;
}
float delta;
float percentOpacity;
float topWindow;
float bottomWindow;
float top;
float bottom;
/*
not visible
--------------------------- top
visible, variable opacity
--------------------------- top window
opacity 100%
-------------------------- bottomWindow
visible, variable opacity
------------------------- bottom
*/
top = self.boundaryRect.origin.y + self.boundaryRect.size.height/2;
topWindow = top - fadeOutZoneHeight_;
bottom = self.boundaryRect.origin.y - self.boundaryRect.size.height/2;
bottomWindow=bottom+ fadeOutZoneHeight_;
if (theY> top ) {
mi.visible=NO;
} else if ( (theY > topWindow) && (theY < top)) {
mi.visible=YES;
delta = abs((int)top - (int)theY);
percentOpacity=delta/fadeOutZoneHeight_;
mi.opacity=(GLubyte )(255.0f*percentOpacity);
} else if( (theY <= topWindow ) && (theY >= bottomWindow ) ){
mi.opacity=255;
mi.visible=YES;
} else if ( (theY < bottomWindow) && (theY >= bottom) ){
mi.visible=YES;
delta= abs((int)bottom - (int)theY);
percentOpacity = delta/fadeOutZoneHeight_;
mi.opacity=(GLubyte ) (255.0*percentOpacity);
} else {
mi.visible=NO;
}
}
Related
Currently I am plotting the graph with two data plots(two lines on the graph), when I click on one line "indexOfVisiblePointClosestToPlotAreaPoint" method giving me right index and other one throwing me wrong one, not even closest visible one its skipping/jumping multiple points in between. Ex: if I click on index number 20 it jumps to 15 or 25 vice versa. Here is the calculation to find the index
-(NSUInteger)indexOfVisiblePointClosestToPlotAreaPoint:(CGPoint)viewPoint
{
NSUInteger dataCount = self.cachedDataCount;
CGPoint *viewPoints = calloc(dataCount, sizeof(CGPoint));
BOOL *drawPointFlags = calloc(dataCount, sizeof(BOOL));
[self calculatePointsToDraw:drawPointFlags forPlotSpace:(CPTXYPlotSpace *)self.plotSpace includeVisiblePointsOnly:YES numberOfPoints:dataCount];
[self calculateViewPoints:viewPoints withDrawPointFlags:drawPointFlags numberOfPoints:dataCount];
NSInteger result = [self extremeDrawnPointIndexForFlags:drawPointFlags numberOfPoints:dataCount extremeNumIsLowerBound:YES];
if ( result != NSNotFound ) {
CGFloat minimumDistanceSquared = CPTNAN;
for ( NSUInteger i = (NSUInteger)result; i < dataCount; ++i ) {
if ( drawPointFlags[i] ) {
CGFloat distanceSquared = squareOfDistanceBetweenPoints(viewPoint, viewPoints[i]);
if ( isnan(minimumDistanceSquared) || (distanceSquared < minimumDistanceSquared)) {
minimumDistanceSquared = distanceSquared;
result = (NSInteger)i;
}
}
}
}
free(viewPoints);
free(drawPointFlags);
return (NSUInteger)result;
}
Are you checking the plot parameter passed in the delegate method? The touch will register on the frontmost plot if there are any points within the plotSymbolMarginForHitDetection. It won't even check the other plot unless nothing hits on the front one. With two lines close together like that, you'll need to use a small hit margin to make sure touches register on the right plot.
Please assist, i have created dynamic content and i need attach scrollbar to it.
Main goal: when scroller reach to bottom my dynamic content bottom must be synchronized with it. (bottom of color boxes must be inline with the scroller)
Scroller size must be the same and don't change height.
How it will be work: if we have 12 boxes for example, slow speed will be used while scroller reach from top to bottom. if 30 boxes for example, it will be faster and so on...
i think so...
Maybe you provide a better solution.
"create dynamic elements layer" section creates color boxes, please check with different quantity
Thank you
jsFiddle
/* move scrollbar and dynamic elements */
verticalBar.on('dragmove', function (e) {
if (verticalBar.x() != verticalBarBottom.x()) {
verticalBar.x(verticalBarBottom.x())
}
if (verticalBar.y() < verticalBarBottom.y()) {
verticalBar.y(verticalBarBottom.y());
}
if (verticalBar.y() > verticalBarBottom.y() + verticalBarBottom.height() - verticalBar.height()) {
verticalBar.y(verticalBarBottom.y() + verticalBarBottom.height() - verticalBar.height());
}
productsOffset = verticalBar.y() - verticalBarBottom.y();
productsStep = products.getClientRect().height / verticalBarBottom.height();
productsStep = products.getClientRect().height / (verticalBarBottom.y() + verticalBarBottom.height());
newYpos = verticalBarBottom.y() - productPadding;
newYpos -= productsOffset * productsStep;
products.y(newYpos);
products.draw();
})
First, you may need to identify how far your left scrollbar is scrolled. I used progress variable (0 <= progress <= 1):
var progress = (verticalBar.y() - verticalBarBottom.y()) / (verticalBarBottom.height() - verticalBar.height());
Then you may need to identify what is min y and max y that layer may take to fit into you required view:
var minY = verticalBarBottom.y() + verticalBarBottom.height() - products.getClientRect().height;
var maxY = verticalBarBottom.y();
You may need to adjust these variables of your use case.
So real y is just somewhere between minY and maxY adjusted by progress:
var y = minY + (1 - progress) * (maxY - minY);
products.y(y);
Demo: https://jsfiddle.net/ehtro20j/
I have a UITextView which contains text and images. I also have a CGPoint array containing coordinates of images added by a user in the UITextFied. Whenever texts in the UITextView changes (addition or deletion), I get the position of the cursor which is a CGPoint object.
Now I want to loop through my CGPoint array to find how many images fall after the cursor position whether on the same line or lines below. How do I go about it?
Any help would be very much appreciated.
Sure:
var cursor = message.caretRectForPosition(message.selectedTextRange?.end).origin;
for i in 0...emoji1.count-1 {
if ((cursor.x > emoji_pt[i].x) && (cursor.y <= emoji_pt[i].y)) {
continue;
}
else {
//the emoji is after the cursor.
// Return the index and process all images after that index
}
}
To handle the Y position
Bool onPreviousLine = (emoji_pt[i].y < cursor.y)
To handle the X position (lineHeight being a constant depending on your case and the size of images, you could probably get away with some low constant value (e.g. 1.0)).
Bool onTheSameLine = abs(Double(emoji_pt[i].y - cursor.y)) < Double(lineHeight / 2)
Bool beforeX = (emoji_pt[i].x < cursor.x)
Together
if onPreviousLine || (onTheSameLine && beforeX) {
continue
}
In my actionscript 3 i have a textfield, which i fill with the messages (get them from the webservice). Not all the messages are visible, so every (for Example) 5s i'm moving them vertically to the top.
To do that, i'm using the Tween effect, but the thing is, that it moves only the visible text and not the rest text together (the invisible one).
When scrolling - i can see the rest text.
Image to show the situation (Sorry for my skills):
Here are some code: Function to fill messages object. Plus count how many lines every message will take to display ( so i could easilly use the tween effect (From - to))
private function getNewMsg(e:ResultEvent):void
{
size = e.result.toString().split(" ").length - 1;
for (var i=0; i<size; i++)
{
smsList.push(new smsItem(e.result[i].Id, e.result[i].text));
}
summ = 0;
for (var d=0; d<size; d++)
{
textfield.appendText(smsList[d].Text.toUpperCase()+'\n');
if (d >= 1)
{
smsList[d].Lines = textfield.numLines - summ;
summ += smsList[d].Lines;
}
else
{
smsList[d].Lines = textfield.numLines-1;
summ += smsList[d].Lines + 1;
}
}
twEnd = smsList[1].Lines * (-30.5);
}
And on timer i'm starting the Tween:
function timerHandler(e:TimerEvent):void
{
myTweenX = new Tween(textfield, "y", None.easeIn, twStart, twEnd, 4, true)
myTweenX.addEventListener(TweenEvent.MOTION_FINISH, tweenCompleted);
}
function tweenCompleted(e:TweenEvent):void
{
twInd++;
twStart = twEnd;
twEnd += smsList[twInd].Lines * (-30.5);
}
Found the problem. Because of my fixed textfield height, text wasn't. After made the textfields height auto size, evrything got fixed.
I have this iOS game where the frog jumps from lily pad to lily pad. The game is in the vertical orientation, and the perspective I'm trying to achieve is an aerial view, where the user looks at the frog and scenery from the top. The frog jumps from lily pad to lily pad and the code is the following:
Bounce Method:
-(void)bounce {
[self jumpSound];
if (frog.center.y > 450) {
upMovement = 2;
}
else if (frog.center.y > 350) {
upMovement = 1.5;
}
else if (frog.center.y > 250) {
upMovement = 0.5;
}
}
and the lilypad movement:
-(void)lilyPadMovement {
if (CGRectIntersectsRect(frog.frame, lily.frame) && (upMovement <=-1)){
[self bounce];
[self lilyPadFall];
if (lilyPadUsed == NO) {
addedScore = 1;
lilyPadUsed = YES;
}
}
}
Essentially what I'm trying to fix is the frogs bouncing movement. When the frog lands in the middle of a lily pad and bounces it doesn't look bad, but at times the frog will simply touch the sides of the lil pad and the bounce method will be called because the rectangles intersected. I tried CGRectContainsRect but it made the game to hard, because it delayed the speed of the game. So I'm not sure how to fix it. Any suggestions?
You really want to know if there's a sufficient overlap to enable the frog to push off, rather than fall in the water. So maybe the distance between the centers has to be less than X, where you tune X based on what looks good.
For example ( using the Pythagorean formula) :
//having defined this function:
inline float square (float a) { return a*a; }
//change intersect test to:
if (((square(frog.center.x-lily.center.x) + square(frog.center.y-lily.center.y)) < 10000) &&
(upMovement <= -1)) { ...