A few newbie questions

I’ve been poking around with the framework for a few days and have a few questions I haven’t found answers to yet. Can anyone answer any/all of the following? Thanks!

  1. I’d like to be able to draw a smaller sub-section of a texture. So rather than calling drawAtPoint (or making a sprite) and having the entire texture drawn, I’d like to be able to give an XY offset and a width/height of the portion of that image I wish to draw. I know you can make a sprite and initialize it with a texture and give the sprite a rect defining this region, but I’m more interested in doing this with a texture object itself rather than a sprite. And no, this doesn’t have anything to deal with atlassing =)
  2. Clipping. I’d like to be able to define a rectangular region where anything drawn outside of said region isn’t drawn and is ignored. Does the framework itself have a mechanism to do this or is this something I need to deal directly with OpenGL on myself?
  3. Is it possible to invert how the Y coordinate works? Presently, Y of 0 is the bottom of the screen and higher values are towards the top. I’d like 0 to be the top of the screen. I would imagine this is part of some initial OpenGL camera set up but I’m not sure if there’s a way with the framework to do this.

Thanks! I’m sure I’ll come up with some others later but this is plenty for now.

About 1 and 2, you should do it by yourself.

  1. I suggesting using current coordinate, because all engine’s logic base on it.

Minggo Zhang wrote:

About 1 and 2, you should do it by yourself.
>
3. I suggesting using current coordinate, because all engine’s logic base on it.

“do it by yourself”?? I tried doing it by myself and didn’t come up with an answer which is why I’m asking the question here. If you know the answer I would appreciate it if you could share it. I was under the impression that the purpose of these forums was to share information regarding the framework.

  1. The sprite is for drawing, you can use it to draw either entire texture or it’s fragment. What for are you “more interested in doing this with a texture object itself rather than a sprite”? Sounds like “I am hungry but do not want to eat”.
  2. The simpliest way is a custom node which is opaque but has transparent window on it.

redaur redaur wrote:

  1. The sprite is for drawing, you can use it to draw either entire texture or it’s fragment. What for are you “more interested in doing this with a texture object itself rather than a sprite”? Sounds like “I am hungry but do not want to eat”.
  2. The simpliest way is a custom node which is opaque but has transparent window on it.
  1. Well one thing that I’ve used in other frameworks is this method of using a much smaller texture to compose a larger thing, sort of like by tiling. It’s commonly used for things like UI elements such as dialog boxes, buttons etc. So imagine you have what will be a large dialog box, but you don’t want to waste space in your atlas by actually having this large, actual size dialog. So we’ve done things like make an image that has its width/height divisible by 3. The corners remain just corners, but you use the center thirds for tiling along the vertical and horizontal. Which allows you to have nice looking and fairly complex appearing dialog boxes (or buttons) but with a very small source asset. Which looks less ugly than taking something plain at a small size and just doing a generic stretch.

It seems like I could use sprites to do this, but I guess my question then is is that the most efficient way to do it? If I used them with the sprite batch node thing, is the performance such that drawing something like say a few dozen or more (all from the same base texture) would be ok? If so, then I could indeed just use sprites which solves the problem.

  1. Sounds good I’ll try that, thanks!

There are some options then:

  • Sprite frames + sprite batch nodes
  • TMX maps + sprite batch nodes
  • Sprite9

redaur redaur wrote:

There are some options then:

  • Sprite frames + sprite batch nodes
  • TMX maps + sprite batch nodes
  • Sprite9

Awesome thanks for the info, man! Appreciate it

What about porting ClippingNode for question 2?

http://www.learn-cocos2d.com/2011/01/cocos2d-gem-clippingnode/

I hope it helps.

Ricardo Silva wrote:

What about porting ClippingNode for question 2?
>
http://www.learn-cocos2d.com/2011/01/cocos2d-gem-clippingnode/
>
I hope it helps.

Actually that looks perfect and pretty easy to port. Thanks for the link.