What's is the best and common way of adding a grid to a Cocos2D game - cocos2d-iphone

I need to add a grid to the background of a game. It should be both zoomable and I should be able to know at which square I am drawing another object now. I need something like this:
What's the most common and proper way of doing this?

Use tileMap(CCTMXTiledMap) inside CCLayerPanZoom. Its easy to track grid clicked and easy to zoom.

Related

How to make splitscreen in Direct2D?

Yesterday I asked a question on how to implement viewport in Direct2D. Now, I know that I could use device->SetTransform() but I also want to 'crop' objects in the window.
What I mean by crop is that so:
would become this:
Basically, I just want to add split screen to my application... Any help?

QGraphicsGrid implementing Drag and Drop / Snap-to functionality

This is a follow-up question of Making an editable flowchart in Qt/C++.
I want to add a QGraphicsItem to a QGraphicsGridLayout in a way that the item takes up its own spot in the grid and then automatically centers in its 'cell'.
I am using QGraphicsView and QGraphicsScene, and drag-and-drop to any location works, but it's looking messy, and could prove to be problematic in future development.
What do I have to do so the item snaps to the grid and centers in its cell?
PS: I have taken a look at http://qt-project.org/doc/qt-4.8/graphicsview-basicgraphicslayouts.html as an example but this didn't help me to solve my problem.
Also, it'd be ideal to have this layout and its data be savable to a text file, etc. I'm assuming a 2D array would be the best way to do this. Should I somehow make the QGraphicsGridLayout based on that array, or is there a better solution?

Best way to have animated background in cocos2d

I have seen some similar questions asked but no definitive answer.
I have a background image that I'm using for my main menu for a cocos2d game. I plan to have it animated but not sure what is the most efficient way to do this. One idea was to have multiple images to create the animation but I was thinking this may take up too much memory as each image would be quite big.
The other idea was having one background image as a sprite and then having child sprites of that image that are animated with ccaction. The only thing is I may not be able to create such an elaborate animation if I do this.
I just wanted to get some feedback on this to see what would be the best approach.
Thank you,
Making a frame-by-frame animation of the whole screen would make your app size litteraly explode.
You should definitely go with your 2nd idea, i.e have different sprites for each animated component and use actions to animate them.
Check out CocosBuilder: it provides a nice UI for designing such complex animations

what's the best way to display images in qt? also I would like to zoom in to particular areas as well

I've been using label to display images. I'd like to be able to click and create a bounding box then be able to drag the cursor to move around in the image. What would I need to do this? Thanks.
I'm not 100% sure I understand what you are trying to do, but I think the QGraphicsScene is what you are looking for. You can (among many other things):
Render images (QGraphicsPixmapItem, for example)
Change the zoom level when rendering the scene on a QGraphicsView.
Select things using a "rubber band"
Move items around with the mouse (see QGraphicsItem::ItemIsMovable)
etc.
You may need to get familiar with Qt's graphics view framework.

Coordinate confusion

I subclassed QGraphicsItem and reimplemented paint.
In paint I wrote something like this for labeling the item:
painter->drawText("Test",10,40);
After some time I think It may be useful to handle labeling with seperate item. So I wrote something like this.
QGraphicsTextItem *label = new QGraphicsTextItem("TEST",this);
setPos(10,40);
But two "TEST" drawing do not appear in the same place on screen. I guess difference may be related with item coordinates - scene coordinates. I tried all mapFrom... and mapTo... combinations inside QGraphicsItem interface but no progress. I want to drawings to appear in the same place on screen.
What I miss?
I assume that you are using the same font size and type in both cases. If the difference in position is very small the reason can be the QGraphicTextItem is using some padding for the text it contains. I would try to use QGraphicsSimpleTextItem that is not going to add fancy stuff internally and see if you still have the same problem. The coordinates system is the same one if you use painter or setPost so that is not the problem. If this doesn't help I will suggest to specify the same rect for both to avoid Qt adding it owns separation spaces.