Problems understanding graphics

I have this problem understanding the basics of graphics on OpenFL.
Okey so there is this thing call sprite… yeah thats the problem i don’t know what it is. Someone can say “it is a MovieClip without a time-line” or “is a 2D image”. That is kind of confusing for me because of this: I know there is this thing call bitmap where we can say the image itself is there. But what i don’t understand is that if the Sprite class loads that and saves it (inside the Sprite class). Then there is this thing call addChild() on the SpriteClass. This addChild adds mores sprites, on the parent sprite, right? lets say i have 2 sprites and the first one addChild()s the second one and that means that the first sprite has modified his bitmap image to have the bitmaps of the other sprite (by this i mean like i painted a car on paper but i want to draw a bird on top of the car so i just draw it on the same paper), right?

Another problem on code that i have is how to use the sprite. If i want to build a tile based map i just draw the tiles from an image using TileSheet draws them on one sprite. Te problem here is that a lot of projects tend to use the sprite class for each tile or any object, and some others just draw everything on one sprite. Which one is better, draw everything on one sprite? or having a sprite class for each object but the idea of the addChild() makes my head hurt and when lets say i want to hide a sprite i cant, it draws everything, the only thing i can do is removeChild() it.

I came from XNA where drawing is just: Load a texture (image) on a variable, then inside the Draw method just call a method to draw the texture. But here in OpenFL drawing (for me) looks different.

Can someone help me understand the concepts? (or maybe i just know the answer from what i said, but im not sure). Thanks for the help. (:

Here’s an example of a situation where sprites help. Let’s say you’ve got a popup of some sort to display. The popup needs to have some text, plus a button or two, and you want it to move around. (For example, check out the popups here.)

First thing you do is, make a “parent” sprite that represents the popup. Put all the text, buttons, and so on inside it (using addChild()).

By setting the x and y coordinates of the buttons and text, you can control their position within the popup. For instance, textField.x = 5 would put the text a short distance from the left edge, and button.y = 85 would put the button near the bottom (assuming the height is ~100).

The cool thing is, you don’t need to update those coordinates when you’re moving the popup. You just set the “parent” sprite’s x and y coordinates, and all the “children” move along with it.

The example I linked to uses the Actuate library to move the popups around smoothly. All it takes is a few lines of code:

popup.y = -popup.height;
Actuate.tween(popup, .2, { y: stage.stageHeight / 2 - popup.height / 2 });

If you want to fade it instead, you can simply switch to the alpha property:

popup.alpha = 0;
Actuate.tween(popup, .2, { alpha: 1 });

Interesting, thanks for the replay, but you just told me a situation where sprites are used and not what a sprite is BUT from what you said i can say that a sprite is like this: sprite = a copy paper, bitmap = pencil drawing. Then multiple sprites are just a bunch of copy papers on top of each other, right? like if i draw multiple buttons on one paper then i can just move the paper and the buttons of course will move with him. (this is just a weird example but i cant understand it like that xD). Is that correct? and also aside from the example on using the sprite for the popups, is it faster (performance) to just use one sprite for everything? and solo i still don’t know how to “hide” a sprite, the options are limited to addChild() and removeChild().

Sprites can be a number of things, but first and foremost, they’re containers. You can’t instantiate the DisplayObjectContainer class directly, but Sprite is a subclass that you can instantiate.

So if you need to package a number of DisplayObjects together for whatever reason, add them as children of a sprite. Here are some sample reasons:

  1. You’re making a popup window (as discussed above).
  2. Your player character carries a sword, and the sword has to stay in the same position relative to the character, but can rotate independently.
  3. You want to specify multiple “layers”: backgrounds in back (natch), characters in front of the background, gfx in front of characters, foreground scenery in front of gfx, and ui in front of everything else. Make five sprites, one for each layer, add objects to the correct sprites, and they’ll automatically show up in the right order.

You can hide a sprite (and all its children) using sprite.visible = false.

Excellent! , of course the paper and drawings where just examples. Also i didn’t saw the “sprite.visible” o.0, Thanks for the help (:

Also I’ve research the DisplayObjectContainer and i found this links for those who are still learning this kind of stuff (like me). This are documentations for flash but its the same idea (: