Using the [CCParallaxNode node] class in cocos2d, I know how to add sprites to the parallax. But I was adding them BEFORE the character started moving with offset set to 0:
[parallaxBack addChild:ground1 z:1 parallaxRatio:CloseElementsSpeed positionOffset:L4];
[parallaxBack addChild:ground2 z:1 parallaxRatio:CloseElementsSpeed positionOffset:L5];
Now, I am trying to add a new sprite after the character has already started to move. I probably don't add the character to the right position.
How can I add a new sprite with an offset to the current position of the parallax? (I have tried to subtract its current position - it didn't work.)
//new sprite after a while - I can't see the character.
[parallaxBack addChild:man z:1 parallaxRatio:CloseElementsSpeed positionOffset:L4];
Related
I'm making a sort of an Excel-type application in which I can load a tab-delimited text file and I am able to edit cells... etc
It's useable but I have an issue related to me allowing the user to "freeze" a number of columns/rows. ("Frozen" rows/columns can only be one of the first ones and are then "frozen", i.e. always displayed even when scrolling)
The whole frozen Col/Row is working but I would like the user to be able to scroll slightly past the last Col/Row in order to be able to only ever display full cells.
Right now when reaching the end of the scrollbar I end up with a partial leftmost column and topmost row because it's only displaying up to the last full col/row and not going a wee bit further for all content to be displayed fully.
I've tried doing adding some space to the maximum scrollbar value once everything is loaded in the table but it seems to have no effect :
table->horizontalScrollBar()->setMaximum(table->horizontalScrollBar()->maximum() + t->horizontalScrollBar()->singleStep()*2);
I tried multiple values too.
(Edit) There may be some Qt code that "snaps" the QTableView viewport back to the edge of the last cell automatically...
(Edit2) I connected verticalScrollbar's rangeChanged() signal to a custom slot with the following code:
void MyTableView::onRangeChanged(int min, int max) {
QScrollBar *sender = verticalScrollBar();
int newVMax = max + 20;
sender->blockSignals(true);
sender->setRange(min, newVMax);
sender->blockSignals(false);
}
Sadly there is definitely a snapback mechanic when scrolling to the end of verticalScrollbar...
Gif of snap back issue
(Edit3) The snap back may be related to:
void QHeaderViewPrivate::setScrollOffset(const QScrollBar *scrollBar, QAbstractItemView::ScrollMode scrollMode)
{
Q_Q(QHeaderView);
if (scrollMode == QAbstractItemView::ScrollPerItem) {
if (scrollBar->maximum() > 0 && scrollBar->value() == scrollBar->maximum())
q->setOffsetToLastSection();
else
q->setOffsetToSectionPosition(scrollBar->value());
} else {
q->setOffset(scrollBar->value());
}
}
mainly:
if (scrollBar->maximum() > 0 && scrollBar->value() == scrollBar->maximum())
q->setOffsetToLastSection();
I have a QTextEdit control. It has a maximum limit (maximum number of characters it can hold). To implement this I have connected a slot to the textChanged() signal which removes the extra character when the total number of characters exceeds the allowed maximum.
With this I have some problems dealing with the cursor position. Can anyone tell me how to retain the cursor position in QTextEdit?
On your slot:
If num of chars exceeds maximum:
Ask the QTextEdit for the Cursor:
QTextCursor QTextEdit::textCursor() const
Set the return value as your textEdit cursor (cause it returns a copy). From doc:
Returns a copy of the QTextCursor that represents the currently visible cursor. Note that > changes on the returned cursor do not affect QTextEdit's cursor; use setTextCursor() to > update the visible cursor.
void QTextEdit::setTextCursor(const QTextCursor & cursor)
Ask the cursor to delete last char
void QTextCursor::deletePreviousChar()
(Edit)as code:
QTextCursor cursor = ui->textEdit->textCursor();
ui->textEdit->setTextCursor( cursor );
cursor.deletePreviousChar();
If number exceeds the limit or wrong character is typed I'm using:
ui->textEdit->textCursor().deletePreviousChar();
Given a QTextBlock retrieved from QPlainTextEdit, I want to change background of the text in that block. I know how to do this with the help of textCursor() but in this case textCursor could be somewhere else. I am traversing through the file text line by line and would like to change background of the current line irrespective of the cursor position. Please let me know if it can be done.
What's the problem with moving the cursor to the line you want to mark?
You can save an old cursor position if you need.
int oldPos = edit->textCursor().position();
QTextCursor cursor = edit->textCursor();
int oldPos = cursor.position();
int linePos = // get the line position
cursor.setPosition(linePos);
cursor.select(QTextCursor::LineUnderCursor);
cursor.setCharFormat(format);
cursor.setPosition(oldPos);
edit->setTextCursor(cursor);
I have a graph that I show two sets of data in it. The user can hit a button to flip to another set of data. The problem is the axes aren't the same, but when I want to update the ticks I instead just layer on top another axis.
http://jsfiddle.net/scottieb/VjHd6/
The key bit is at the end:
vis.selectAll("axis").remove();
vis.append("svg:g")
.attr("class", "x axis")
.attr("transform", "translate(0, " + (h - margin ) + ")")
.call(d3.svg.axis()
.scale(x)
.tickSize(0)
.tickSubdivide(true)
.tickFormat(formatCurrency)
);
I've tried selectAll("g").remove(), but that prevents laying down the next axis. Any ideas?
Whoops, needed to redefine the scale and call a transition rather than just build a whole new axis.
http://jsfiddle.net/scottieb/JwaaV/
Your issue is that your selector is not correct. Instead of selecting "axis", you should select ".axis" since you are appending a "g" node with a class.
convertToWorldSpace
Hi, I'm not sure I understand how this works.
The api states that it converts local coordinate to world space.
Let' say I have three sprites. spriteA added to scene , and spriteB added to spriteA. And spriteC added to spriteB.
- Scene
- spriteA
- spriteB
- spriteC
And I want to convert spriteC origin to world
If I do: [self convertToWorldSpace:[spriteC CGPointZero]];
or this: [spriteA convertToWorldSpace:[spriteC CGPointZero]];
or this: [spriteB convertToWorldSpace:[spriteC CGPointZero]];
or even [spriteC convertToWorldSpace:[spriteC CGPointZero]];
Shouldn't they all give the same answer since they are all transformed to world coordinates? Or do I go from one node space to parent node space ...until I get to world space.
what is the correct answer to see spriteC position in world coordinates?
To find the world space origin on spriteC, you take the sprites parent, in this case spriteB and ask for the world space of its child:
[spriteB convertToWorldSpace:[spriteC CGPointZero]];
[spriteC convertToWorldSpace:CGPointZero];
As Kazuki answer but CGPointZero is a global.
[spriteC convertToWorldSpace:[spriteC CGPointZero]];
convertToWorldSpace: method converts one node space to parent node space ... until it gets to world space.