Can't access variable declared by SpriteBuilder - cocos2d-iphone

I'm doing this tutorial.
To separate menu button and game content I added a CCNode named _contentNode that include all gaming content and publish it to XCode as the tutorial indicated.
But I get Use of undeclared identifier '_contentNode' error when I try to run it in XCode.
This is the SpriteBuilder screenshot how I set the variable. Is there something wrong with this?

I forgot I must declare variable in the code like this:
#implementation Gameplay {
//...
CCNode *_contentNode;
}

Related

SFML : drawing from different files

I'm working on a SFML project that contains several different files and classes. The problem is : in every file, there is some drawing, and the sf::RenderWindow* defined in the main file seems to be out of scope here, therefore I can't link these drawing with the main window. I've tried to redefine sf::RenderWindow in every header files, and it doesn't work as well (a black screen appear and disappear promptly). The error was : Access violation reading location. But when I group everything in one file, things work well but it looks really messy.
I also found this question asked on another forum, and the answers were "using reference and external method", which is a bit vague to me. Any help on this linking problem would be appreciated :(
I think that answer meant something like:
void draw_in_class (sf::RenderWindow* window){
window->draw(...);
}
in class, and then you can use 'draw_in_class' in main:
#include"class.h"
... // Define sf::RenderWindow here
draw_in_class(&window);

wxWidgets - Splitting project into multiple files

I am very new to C++, I'm making this music application using wxWidgets, this is my first project in C++. As of now, I have 4 files, app.hpp and app.cpp which has a class that inherits from wxApp that launches the application, and frame.hpp and frame.cpp which holds the base frame and panel, and all the widgets, and their appropriate functions. I want to move all the functions to a separate file, but I get some errors like there is this function in frame.cpp
void Frame::ClearPlaylist(wxCommandEvent& event)
{
mediaCtrl->Stop();
playlistBox->Clear();
}
I tried moving it in another file called command.cpp and created a new class called command and prefixed all functions to Command:: .... and somethings like the playlistBox here, is a widget which I want in frame.cpp only, as it is a widget, so I did #include frame.hpp and prefixed it with Frame::playlistBox, but that gave a error saying invalid use of non static data member. So do I have to make everything in frame.hpp a static object? Or if anyone has a better solution for organizing a project like this please do share.

cant get a pointer to wxwidget object, using wxsmith

straight to the point:
Im learning wxsmith and wxwidgets toolkit, i created some basic GUI containing one button and 2 static text fields. GUI is compilling ok so far. My frame name is proba2Frame, then im adding my own function which is not a member of any class but i declared in header file for proba2Frame that my function is a friend. Below is code of my function:
wxStaticText * dawajpointera()
{
wxStaticText * text;
text = proba2Frame.wxStaticText.StaticText1;
return text;
}
im getting error:
expected primary-expression before ‘.’ token
What exactly im doing wrong and how to get a pointer StaticText in case my solution is completely wrong ?
Thank You in advance
You make it sound like proba2Frame is the name of a class inheriting wxFrame?
If so, you're haveing problems because you haven't created an instance of proba2Frame, and you're trying to access a part of it that hasn't been constructed. Your main frame class is simply a template for your GUI, not the GUI itself.
The best way to go about it would probably be to take an instance of proba2Frame as a parameter-
wxStaticText* dawajpointera(proba2Frame *frame)
{
return frame->StaticText1;
}
Of course, that function itself was a bit pointless, but I'll assume that you're going to do something more involved with the pointer afterwards, and want it set to a pointer named text within the function for the sake of brevity.
void func(proba2Frame *frame)
{
wxStaticText *text = frame->StaticText1;
// Do something with text
}
If you're doing this, though, please consider making the function a method of proba2Frame.
wxStaticText is the name of a wxWidgets class. You should not be naming attributes of your frame 'wxStaticText'. Despite the code you have posted, I doubt that you have really done such a terrible thing. What you probably meant to write, I would guess, is:
text = proba2Frame.StaticText1;
I am guessing that the name of the attribute is StaticText1, a pointer to an instance of the wxStaticText class.

cocos2d-x CCTouchDispatcher - no sharedDispatcher

I'm currently porting an ObjC cocos2d game to cocos2d-x, but I'm encountering some problems when trying to create a registerWithTouchDispatcher method, at the moment I'm doing
void GameLayer::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,0,true);
}
but this gives an error 'No member named sharedDispatcher' in cocos2d::CCTouchDispatcher'.
Is there another way that this must be done in cocos2d-x?
If you are using 2.0, they have been merged in to CCDirector.
please use
CCDirector::sharedDirector()->getTouchDispatcher()
use those code instead ccdirector. put the code to cclayer init function.
setTouchMode(kCCTouchesOneByOne);
registerWithTouchDispatcher();
In the cocos2d-x you can do like this.
CCDirector::sharedDirector()->getTouchDispatcher()->addStandardDelegate(this,0);

Expected specifier-qualifier-list before... Error in C++/Objective-C iPhone project

So I'm going through the first tutorial in O'Reilly's iPhone 3D Programming book. At this point in the tutorial, it pulls all the OpenGL ES stuff into a seperate c++ interface. I have followed the book to the letter, as far as I can tell, yet I can't seem to figure out this compiler error. I'm fairly new to C++ (mostly C# in the past), so I'm sure it's something stupid.
Below is the current state of all the relevant files.
I have a c++ header file called IRenderingEngine.hpp with the following contents:
enum DeviceOrientation {
Unknown,
Portrait,
PortraitUpsideDown,
LandscapeLeft,
LandscapeRight,
FaceUp,
FaceDown,
};
struct IRenderingEngine* CreateRenderer1();
struct IRenderingEngine {
virtual void Initialize(int width, int height) = 0; //Compiler error "expected specifier-qualifier-list before 'virtual'
virtual void Render() const = 0;
virtual void UpdateAnimation(float timeStep) = 0;
virtual void OnRotate(DeviceOrientation newOrientation) = 0;
virtual ~IRenderingEngine() {}
};
I have an objective-c/c++ header file called GLView.h that looks like this:
#import "IRenderingEngine.hpp"
#import <OpenGLES/EAGL.h>
#import <QuartzCore/QuartzCore.h>
#interface GLView : UIView {
EAGLContext* m_context;
IRenderingEngine* m_renderingEngine; //Compiler error: Expected specifier-qualifier-list before "IRenderingEngine"
float m_timeStamp;
}
- (void) drawView: (CADisplayLink*) displayLink;
- (void) didRotate: (NSNotification*) notification;
#end
And finally, a GLView.mm file with a barebones implementation:
#import "GLView.h"
#implementation GLView
+ (Class) layerClass
{
return [CAEAGLLayer class];
}
- (id)initWithFrame:(CGRect)frame {
return self;
}
- (void) drawView:(CADisplayLink *)displayLink
{
}
-(void) didRotate:(NSNotification *)notification
{
}
#end
You need to rename HelloArrowAppDelegate.m to a .mm file. It states in the book on page 20 (middle section with the paws bullet point). I missed that section and had the same problem. After changing the file to .mm the program worked.
This error message e.g. occurs if one of your two headers gets included in a plain Objective-C source file, which doesn't know anything about handling C++ code.
To allow GLView to be used from plain Objective-C sources, use only a forward declaration for the rendering engine and don't include the C++ header in GLView.h:
// GLView.h:
struct IRenderingEngine;
#interface GLView : UIView {
struct IRenderingEngine* m_renderingEngine;
// ...
#end
// GLView.mm:
#import "IRenderingEngine.hpp"
// ... etc.
Alternatively you can use opaque pointers for wrapping C++ instances to keep the Objective-C interface more stable, see e.g. Rob Napiers post on the subject.
When this is fixed, you still need to fix the declaration for CreateRenderer1() as others pointed out - either forward-declare struct IRenderingEngine; before the function or just move it after the definition of the struct.
I had the exact same problem. It turned out to be due to the fact that renaming HelloArrowAppDelegate.m to HelloArrowAppDelegate.mm in Xcode's Groups & Files did not actually rename the file! Once I used Finder to rename it the project compiled OK. Note Xcode may complain that the HelloArrowAppDelegate.m is missing when you open the project again, just right click it, delete it and then use "Add existing files" to add the HelloArrowAppDelegate.mm file back in.
This may seem a cop-out but I had exactly the same problem when I updated to XCode 4.x
I got around it by downloading the source code from O'reilly's website and just loaded the project. Xcode appeared to recognise it as an old project and configured itself accordingly; no compilation issues, worked first time. It's not the same as typing it in yourself but it works.
The line
struct IRenderingEngine* CreateRenderer1();
Must come after the declaration of the IRenderingEngine class. (Also, if you intended to use the variable as a pointer to that structure type you should omit the parentheses in its declaration.)
For your other error I think you want to prepend the line with struct.
I believe this line is causing the error:
struct IRenderingEngine* CreateRenderer1();
I'm not quite sure what you're trying to do there, but I think it should be removed entirely.