@saim80 Still did not work for the latest version of cocos2d.
The error is: "CCDirector May Not Respond to contentScaleFactor".
What to do to fix this?
Thank you for a while.
A fast, easy to use, free, and community supported 2D game engine
@saim80 thanks for this class, I'm sure it must have been pretty cool back in the before-1.0 days. I, like most, would really like to use this in the current version of the engine, but can't. Please, could you update the source? Or could you or someone please provide some type of explanation as to how to use this, along with what to do with the lack of that debug file? I really wanted to use a table view inside my game, and really feel like this could be the answer. Thank you.
@saim80 seems a little busy so I've added a very simple vertical table view test (based on some of his own sample code). It's using cocos2d 1.0 (it may have been the last release candidate prior to officially going 1.0). You can find it here:
https://github.com/porumbes/Cocos2D-Extensions
Look in SWSimpleTableViewTest.h/.m
Hope that helps!
Hey guys,
I had the problem of wrong clipping on iphone4 (only) so i fixed it by overidding before and afterdraw in SWScrollView.
I use gl_CLIP_PANE instead of GL_SCISSOR for the iphone 4.
cocos2d is 1.0.0 and SWTableView is taken from github
Here are the modifications:
SWScrollView.m:
-(void)beforeDraw {
if (clipsToBounds_) {
if([CCDirector sharedDirector].contentScaleFactor == 2)
{
GLfloat width;
GLfloat height;
width = viewSize_.width*2;
height = viewSize_.height*2;
GLfloat planeTop[] = {0.0f, -1.0f, 0.0f, height};
GLfloat planeBottom[] = {0.0f, 1.0f, 0.0f, 0.0f};
GLfloat planeLeft[] = {1.0f, 0.0f, 0.0f, 0.0f};
GLfloat planeRight[] = {-1.0f, 0.0f, 0.0f, width};
glClipPlanef(GL_CLIP_PLANE0, planeTop);
glClipPlanef(GL_CLIP_PLANE1, planeBottom);
glClipPlanef(GL_CLIP_PLANE2, planeLeft);
glClipPlanef(GL_CLIP_PLANE3, planeRight);
glEnable(GL_CLIP_PLANE0);
glEnable(GL_CLIP_PLANE1);
glEnable(GL_CLIP_PLANE2);
glEnable(GL_CLIP_PLANE3);
}
else
{
glEnable(GL_SCISSOR_TEST);
const CGFloat s = [CCDirector sharedDirector].contentScaleFactor;
glScissor(self.position.x, self.position.y, viewSize_.width*s, viewSize_.height*s);
}
}
}
/**
* retract what's done in beforeDraw so that there's no side effect to
* other nodes.
*/
-(void)afterDraw {
if (clipsToBounds_) {
if([CCDirector sharedDirector].contentScaleFactor == 2)
{
glDisable(GL_CLIP_PLANE0);
glDisable(GL_CLIP_PLANE1);
glDisable(GL_CLIP_PLANE2);
glDisable(GL_CLIP_PLANE3);
}
else
glDisable(GL_SCISSOR_TEST);
}
}
Hope it helps.
Pit
Pit!
This "little" piece of code saved my life!
Thanks a lot man!!
What a relief!
I think you should definitely add this code to github repo!
@Serban, thanks for that code.
A couple modifications need to be made in the tableview test for the sprites to be displayed correctly. The anchor point of the sprites needs to be 0,0 or else they will disappear too early in the scrolling direction (y) and be cut off in the other (x). Also the size of the cells should be 57, 57 for the images used in the test. I hope this helps anybody using the github code.
Also, is it possible to display scroll bars in either the scroll view or table view?
Hello everybody. I have a problem with SWTableView. I have two SWTableView in one class. When one of SWTableView have zero number of cell, that object of SWTableView still in into -table:cellAtIndex: and made my application crash. But when the other one have zero number of cell it's working fine. Anyone know why?
Thanks for attention. Regards. :)
I found a small issue with scroll view. I was trying to put a CCScrollview into a layer that was not located at position 0, 0. When I set the content of my scroll view and tried to scroll it was only accepting touches in an area equivalent to if my layer (and thus my scroll view) were at 0,0. Found the issue and fixed it. Would have added to github, but it seems like that still has code in it with the old naming convention (i.e. SWScrollView).
in scroll view replace the touches began and touches moved with:
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (!self.visible) {
return;
}
CGRect frame;
frame = CGRectMake(self.position.x, self.position.y, viewSize_.width, viewSize_.height);
//dispatch does not know about clipping. reject touches outside visible bounds.
for (UITouch *touch in [touches allObjects]) {
//CGPoint NodeSpace = [self convertTouchToNodeSpace:touch];
if (!CGRectContainsPoint(frame, [self convertTouchToNodeSpace:touch])) {
touchPoint_ = ccp(-1.0f, -1.0f);
isDragging_ = NO;
return;
}
}
if ([touches count] == 1) { // scrolling
touchPoint_ = [self convertTouchToNodeSpace:[touches anyObject]];
} else { // 2 or more touches would mean something else?
//invalidate initial values
touchPoint_ = ccp(-1.0f, -1.0f);
}
touchMoved_ = NO;
isDragging_ = YES; //dragging started
scrollDistance_ = ccp(0.0f, 0.0f);
}
-(void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
if (!self.visible) {
return;
}
touchMoved_ = YES;
if ([touches count] == 1 && !CGPointEqualToPoint(ccp(-1.0f,-1.0f), touchPoint_) && isDragging_) { // scrolling
CGPoint moveDistance, newPoint, maxInset, minInset;
CGRect frame;
CGFloat newX, newY;
frame = CGRectMake(self.position.x, self.position.y, viewSize_.width, viewSize_.height);
newPoint = [self convertTouchToNodeSpace:[touches anyObject]];
moveDistance = ccpSub(newPoint, touchPoint_);
touchPoint_ = newPoint;
if (CGRectContainsPoint(frame, newPoint)) {
switch (direction_) {
case CCScrollViewDirectionVertical:
moveDistance = ccp(0.0f, moveDistance.y /* /CC_CONTENT_SCALE_FACTOR() */);
break;
case CCScrollViewDirectionHorizontal:
moveDistance = ccp(moveDistance.x /* /CC_CONTENT_SCALE_FACTOR() */, 0.0f);
break;
default:
break;
}
container_.position = ccpAdd(container_.position, moveDistance);
if (bounces_) {
maxInset = maxInset_;
minInset = minInset_;
} else {
maxInset = [self maxContainerOffset];
minInset = [self minContainerOffset];
}
//check to see if offset lies within the inset bounds
newX = MIN(container_.position.x, maxInset.x);
newX = MAX(newX, minInset.x);
newY = MIN(container_.position.y, maxInset.y);
newY = MAX(newY, minInset.y);
scrollDistance_ = ccpSub(moveDistance, ccp(newX - container_.position.x, newY - container_.position.y));
[self setContentOffset:ccp(newX, newY)];
}
}
}Which is the latest version, the one with the CC prefix or the SW prefix? Do you have a link to it? Also has anyone got the ScrollView and TableView working correctly under the latest version of Cocos2d V1.0.1? Would really like to use this for my store!!
@andrewgold99, I have successfully used classes that @Serban shared a couple posts above. I use cocos2d 1.0.0.rc3.
It works ok, but I had *huge* problems running it in landscape mode. I finished with manually rotating and positioning every child in the layer.
Hi all,
How can I set CCTableView's background transparent? Just like UITableView's [tableView setBackgroundColor:[UIColor clearColor]] or [cell setBackgroundColor:[UIColor clearColor]]. I didn't find such method in CCTableView.
Thanks!!
I'm using cocos2d 0.9.5 and whenever I add a scrollview to the node it will drop the FPS of the game by half. Max I can get is 30.
Is this something normal? where is this coming from?
List can have like 2 elements, but the fps will drop to 30 anyway.
Anyone having performance issues?
Once I open a window [CCNode] where I have the table view frame rate drops significantly - from 60 to 30fps. Open another one: 30 to 20...
I'm not sure what could cause that, any hints?
One more question: how do I reload a table view? I've made some changes to the data used by the table view and I want the table to show this changed data.
There's a reloadData method, but it does not work as I would expect it to.
In order to refresh the table I have to remove it and recreate it, which as you might expect is a bit of a problem.
Maybe my previous post was not descriptive enough.
When I have a table with let's say 5 entries, all of them are visible on screen. I keep the data in some array - the datasource.
I remove one entry from the datasource and run reloadTable.
What I get on screen is the same table, with all the elements as they were and one entry missing. I would expect the table to be redrawn so that there is no 'blank' space between elements. When I try to scroll the table everything is put into place.
What am I missing?
Simulating touch begin, moved, end after each reload seems like a crappy idea.
Hi, I've been using the CCTableView and have been making good progress with my work until I needed to put an image that would only show up at the TableCell that is at index 0 (at the top). I've added the image to the TableCell at index 0 but it repeats itself every 3 TableCells. I have a list of 10 items and it shows up on 0, 3, 6, and 9. Anyone have any clue why it does this? While debugging I only see the image get added once at the 0th index
@ragnarok513 paste some of your code [especially the one responsible for creation of the cells]
Sounds like the cell's being reused and the imageview isn't being cleared out.
here's my code, i add the top boundary after the comment "create the top of the scroll bar"
'-(SWTableViewCell *)table:(SWTableView *)table cellAtIndex:(NSUInteger)idx {
SWTableViewCell *cell = [table dequeueCell];
if (!cell) {
cell = [[MyCell new] autorelease];
}
CCSprite *sprite = [CCSprite spriteWithFile:@"100x100blank.png"];
sprite.anchorPoint = CGPointZero;
sprite.position = ccp(20, 20);
[cell addChild:sprite];
// create scrollbar
for(int i = 0; i <= 130; i += 20)
{
CCSprite *dot = [CCSprite spriteWithFile:@"10x10blank.png"];
dot.anchorPoint = CGPointZero;
dot.position = ccp(420, i);
[cell addChild:dot];
CCSprite *dot2 = [CCSprite spriteWithFile:@"10x10blank.png"];
dot2.anchorPoint = CGPointZero;
dot2.position = ccp(0, i);
[cell addChild:dot2];
}
// create the top of the scroll bar
if(idx == 0)
{
CCSprite *end = [CCSprite spriteWithFile:@"430tabletop.png"];
end.anchorPoint = CGPointZero;
end.position = ccp(0, 120);
[cell addChild:end];
}
return cell;
}'
Sorry, I was thinking in UITableViews. I haven't used CCTableViews so I'm not sure if you'd have a similar reuse problem.
SWTableViewCell *cell = [table dequeueCell];
if (!cell) {
cell = [[MyCell new] autorelease];
}
CCSprite *sprite = [CCSprite spriteWithFile:@"100x100blank.png"];
sprite.anchorPoint = CGPointZero;
sprite.position = ccp(20, 20);
[cell addChild:sprite];
This means, that nevermind whether you already had the cell or not, you will add the sprite and put it in the same position.
I think you should consider changing the code to retrieve already existing sprites on the cell to reuse them or remove them before adding new ones.
Check this thread for an example from Ray and later fix for his example [don't remember author's name] to see how this can be done.
This piece of code that was posted in an earlier post fixed my issue
if (!cell) {
cell = [[MyCell new] autorelease];
} else {
[cell removeAllChildrenWithCleanup:YES];
}Is this class still being developed? I keep getting a crash when I click/drag my tableview. It fails on
[delegate scrollViewDidStartDragging]
method not found. I thought the class is supposed to handle scrolling for us?
Also how do I specify which column the data source is returning?
I never got this error and I am using table view extensively. What do you mean about the column?
When table view is generated [and when cells reappear on screen]
-(SWTableViewCell *)table:(SWTableView *)table cellAtIndex:(NSUInteger)idx
is called. So you get the idx which you normally use to get object from array [data source].
If you want to know which column it is you can do:
idx % numberOfColumns
0 would mean last column though
Thanks krstn, that makes sense with the columns. I think the app has moved in a slightly different direction, but I'll keep this info in mind with future updates.
I tried to use the CCTableView but can't compile!
Please can one upload a working xcode project with correct/update code?? Thank you :)
You must log in to post.