cocos2d & CAShapeLayer objects - cocos2d-iphone

My class X is interited from CCLayer.
#interface X : CCLayer
Then in X, I added an instance variable of type CAShapeLayer.
CAShapeLayer *_Circle
I drew the Circle using UIBezierPath. Now if I try to add _circle to self, it gives me error:
[self addChild:_Circle];
[CAShapeLayer tag]: unrecognized selector sent to instance 0x916f7f0
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CAShapeLayer tag]:
unrecognized.
I also tried typecasting _Circle to (CCNode*) or (CCSprite*) but nothing helped.
Please advise.

Related

Word Document in QAxWidget doesn't have scrollbars

I'm displaying a word document in QAxWidget.
QAxWidget *axWidget = new QAxWidget;
axWidget->setControl(changelogTempFile->fileName());
axWidget->setFixedSize(400,300);
axWidget->show();
However eventough the whole document does not fit in the viewport I have no scrollbars.
I even tried to use Frameset object to explicitly add scrollbars but it was in vain.
QAxObject *frame = ui->axW_singleChl_doc->querySubObject("Frameset");
if( frame )
frame->setProperty("FrameScrollbarType","wdScrollBarTypeYes");
I received following error message:
QAxBase: Error calling IDispatch member Frameset: Exception thrown by server
Code : 6027
Source : Microsoft Word
Description: Die Eigenschaft Document.Frameset ist nur verf?gbar, wenn Document.Type WdFrameset entspricht
Help : wdmain11.chm [25507]
Connect to the exception(int,QString,QString,QString) signal to catch this exception
Description translated means, that property Document.Frameset is only available if Document.type is WdFrameSet
How can this be achieved? Many thanks in advance,
James

Get the parameters of a drawn circle over an ImageWidget

I'm trying, like I said in the title, to get the parameters of a circle drawn with guiqwt.tools.CircleTool. I add that tool to the ImageWidget I create, and when you click over the widget, the circle it's drawn. But, as I want to get the coordinates, I have to extend the ImageWidget class so that when the left button it's released, a signal is emitted, in order to connect to a function where it's done all the stuff.
That's the extended class:
class ExtendedImageWidget(ImageWidget):
def mouseReleaseEvent(self, event):
if event.button() == QtCore.Qt.LeftButton:
self.emit(QtCore.SIGNAL('clicked()'))
The code to connect with the function:
QtCore.QObject.connect(self.imagewidget, QtCore.SIGNAL('clicked()'),self.selection_tools)
And finally the function:
def selection_tools(self):
print('inside selection_tools')
if self.selectCircle.action.isChecked()==True:
print('inside selectCircle')
tamListaItems=len(self.imagewidget.plot.items)
self.circulo=self.imagewidget.plot.items[tamListaItems-1]
#Remove any item other than an image or the grid
for i in range(1,tamListaItems)[::-1]:
if type(self.imagewidget.plot.items[i]) != type(self.imagewidget.plot.items[1]):
self.imagewidget.plot.del_item(self.imagewidget.plot.items[i])
#Add the last item drawn
self.imagewidget.plot.add_item(self.circulo, autoscale=False)
self.imagewidget.plot.replot()
#Get and print some parameters
circle=self.selectCircle.get_final_shape()
print('circle',circle)
self.center=circle.get_center()
ptsDiameter=circle.get_xdiameter()
print('center',self.center)
print('ptsDiameter',ptsDiameter)
self.radius=np.int(np.round((np.sqrt(np.square(ptsDiameter[0]-ptsDiameter[2]) + np.square(ptsDiameter[1]-ptsDiameter[3])))/2))
print('radius',self.radius)
The issue is that, the first circle I draw (It is drawn, and detected as an item in the ItemList), I got nothing at the output. The second I draw, I get the parameters of the previous circle. Here and example of the output I get:
inside selection_tools
inside selectCircle
('circle', <guiqwt.shapes.EllipseShape object at 0x0C6AA978>)
('center', (106.88683969465652, 148.08916030534348))
('ptsDiameter', (64.703511450381697, 101.00079389312975, 149.07016793893132, 195.17752671755721))
('radius', 63)
inside selection_tools
If I change:
circle=self.selectCircle.get_last_final_shape()
by:
circle=self.selectCircle.get_final_shape()
The signals seems to be working well, because when I draw a circle, I instantaneously get printed the notifications "inside selection_tools" and "inside selectCircle", but it doesn't return to any parameter.
If someone could help me it would be great.
Thanks in advance.

how to create menu using a sprite sheet in cocos2d-x

I just started learning cocos2d-x.
I am trying to create menu using sprite sheet, below:
CCSpriteFrameCache::sharedSpriteFrameCache()>addSpriteFramesWithFile("my_menu.plist");
CCMenuItem *play = CCMenuItemImage::create("play.png", NULL,NULL,this , menu_selector(StartScene::clickStart));
CCMenu *pMenu = CCMenu::create(play,NULL);
addChild(pMenu);
I got error message:
get data from file (play.png) failed.
I realise something wrong with my create function. I am just wondering how to get the image from sharedSpriteFrameCache?
OK, I just figure it out:
CCMenuItemSprite *play = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("play.png"), NULL,NULL,this ,menu_selector(StartScene::clickStart));
spriteWithSpriteFrameName is deprecated, instead, we can use:
CCSprite::createWithSpriteFrameName();
u need to take the plist file in a ccspritebatchnode object and manipulate it using this object.
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:#"AnimBear.png"];
[self addChild:spriteSheet];

Ocaml : exception Graphics.Graphic_failure("Xlib error: BadPixmap (invalid Pixmap parameter)")

I've a problem with a little function in caml.
Here my function :
let show img =
let h = height img in
let w = width img in
open_graph (" "^string_of_int w^"x"^string_of_int h);
set_window_title "Seam Carving";
draw img;
if Graphics.key_pressed() then
match Graphics.read_key() with
| 'q' -> close_graph()
| _ -> ()
;;
When I clicked on the button 'q', I've this error :
Fatal error: exception Graphics.Graphic_failure("Xlib error: BadPixmap (invalid Pixmap parameter)") or segmentation fault.
Someone can to explain me the reason of a such error ? Thanks :)
There will be no reply to your question, as there is not enough information in it.
In general, if you experience a Segmentation Fault with OCaml, it is a MAJOR BUG, so you should fill a bug report on OCaml bug tracker, and upload a program reproducing the error.

ContactListener box2d cocos2d contacted body property

I have Building CCNode
It's have property:
in .h file
#property (nonatomic) int testProperty;
in .mm file add tag and set property
[[GB2ShapeCache sharedShapeCache] addShapesWithFile:#"Objects.plist"];
[CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
batchNode = [CCSpriteBatchNode batchNodeWithFile:#"sprite.png"];
[self addChild:batchNode];
[[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:#"sprite.plist"];
sprite = [CCSprite spriteWithSpriteFrameName:[NSString stringWithFormat:#"%#.png", type]];
[batchNode addChild:sprite];
[sprite setTag:2]; //SET TAG
[self setTestProperty:10]; //SET PROPERTY
...
Also is the ContactListener class
It's work correctly with this code and i'm detecting body by tag fine:
#import "ContactListener.h"
#import "Building.h"
void ContactListener::BeginContact(b2Contact* contact)
{
b2Body* bodyA = contact->GetFixtureA()->GetBody();
b2Body* bodyB = contact->GetFixtureB()->GetBody();
Building *buildA = (Building *)bodyA->GetUserData();
Building *buildB = (Building *)bodyB->GetUserData();
if (buildA.tag == 2) {
NSLog(#"Collision with building");
}
}
PROBLEM:
I don understand how get property from ContactListener
I tried to get it so:
if (buildA.tag == 2) {
NSLog(#"Collision with building");
NSLog(#"testProperty == %i", buildA.testProperty);
}
But buildA.testProperty not work, and get error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CCSprite testProperty]: unrecognized selector sent to instance 0x434af0'
If your can explain my please how get property from this class. Thanks.
'-[CCSprite testProperty]: unrecognized selector sent to instance 0x434af0'
You store the CCSprite in userdata, not the Building object.
You set the tag like this, then of course checking for the correct tag works:
[sprite setTag:2];
But this is incorrect because user data is not a Building but a sprite:
Building *buildA = (Building *)bodyA->GetUserData();
I assume that Building inherits from CCSprite, this is why accessing the common properties like tag works, but not the Building specific properties.
When I create body, I set into user data sprite.
In the Building.h
body->SetUserData(self);
solved the problem.