00:00
00:00
Newgrounds Background Image Theme

punk563 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Big Artwork In Swc

462 Views | 6 Replies
New Topic Respond to this Topic

Big Artwork In Swc 2013-10-29 18:58:30


My current flash has a lot of artwork and assets. I know I could use a separate .fla file then export it as a SWC to minimize the file size (and loading) of the main file. Unfortunately I have classes that are associated to artwork (such as a movieclip with class name "Tree" and a base class of "some.path.to.TreeBase")

I don't really want to include all of my AS in the SWC (that's what the main file is for), but how do I still allow base classes of custom classes without including them in the SWC?

Does that make sense? Thanks.


BBS Signature

Response to Big Artwork In Swc 2013-10-29 19:35:35


Export all classes to simple codeless graphical shells.
Export tree movie clip to Tree_design. Do not make it have any base class besides MovieClip. Or Sprite.
Separate all code from graphics.
You need a more careful way of using Flash as a simple level editor for tree placement, if you do not want to mix code with game graphics. Otherwise you won't be able to compile your project without recompiling the art part of it every time.
I recommend using containers for just carrying data.
Let's say you have 3 different kinds of trees placed inside a some exported level symbol. The trees are just there, no instance names, nothing fancy set to them, no base classes. Then in FD you have code to read this data, using:

for(i=0;i<numChildren;i++){
  var tree:DisplayObject=getChildAt(i);
  if(tree is Tree1_design)new Tree(Tree1_design,tree);
  if(tree is Tree2_design)new Tree(Tree2_design,tree);
  if(tree is Tree3_design)new Tree(Tree3_design,tree);
}

A more compact and maintainable code of the same thing would be:

var allowedTreeTypes:Array=[Tree1_design,Tree2_design,Tree3_design];
for(i=0;i<numChildren;i++){
  var tree:DisplayObject=getChildAt(i);
  for(j=0;j<allowedTreeTypes.length;j++){
    if(tree is allowedTreeTypes[j])
      new Tree(allowedTreeTypes[i],tree);
  }
}

But I'm not sure if it will even compile because of "is" operator.
Then you have the Tree class something like this:

package{
  public class Tree extends Sprite{
    public function Tree(type:Class, position:DisplayObject){
      x=position.x; y=position.y;
      addChild(new type());
    }
  }
}

But MSGHero probably knows a better way to do this, and has more knowledge working with SWCs/FD than me.

Response to Big Artwork In Swc 2013-10-29 19:42:52


Okay I see what you're saying. Instead of assigning a base class to every design element, have the class have a "var tree_design:MovieClip;" variable that contains the tree graphic. Well, in your example you added it as a child to the tree, but I want to minimize the number of symbols.

Interesting. I wonder if this is the best way to go about this?


BBS Signature

Response to Big Artwork In Swc 2013-10-29 19:58:54


The very best way is all this, plus a custom-made level editor which saves/loads XML containing level data.
Using custom level editors will enable you to modify game levels without recompiling SWC. If you were using Flash IDE to edit levels, you'd have the level as a symbol which would need to be compiled in an SWC, forcing you to recompile everything else along with it.
Besides, you don't really have a choice, if you want to not recompile the SWC every time you change code.

Unless you could find a way to move classes outside of your SWC, you can't just modify a base class and expect FD to make changes to it in the SWC automatically. Or... can you?

Whoah, you got me confused. This is a sign of a serious problem.

Response to Big Artwork In Swc 2013-10-29 20:04:10


At 10/29/13 07:42 PM, coln wrote: Okay I see what you're saying. Instead of assigning a base class to every design element, have the class have a "var tree_design:MovieClip;" variable that contains the tree graphic. Well, in your example you added it as a child to the tree, but I want to minimize the number of symbols.

Interesting. I wonder if this is the best way to go about this?

I divorce my assets from the class they're a part of. My Tree class would have a "mc" property, and I would set that to be a new "Tree_MC_from_SWC()." Tree_MC's base class would be a movieclip. It's not the only way, but I'm pretty comfortable with doing it this way.

I don't know how swcs work in great detail, but including the custom base classes doesn't really matter, if it even includes them at all. In flash pro, add your src folder to the project classpath to have access to the files.

Response to Big Artwork In Swc 2013-10-29 20:12:25


At 10/29/13 08:04 PM, MSGhero wrote: I divorce my assets from the class they're a part of. My Tree class would have a "mc" property, and I would set that to be a new "Tree_MC_from_SWC()." Tree_MC's base class would be a movieclip. It's not the only way, but I'm pretty comfortable with doing it this way.

I don't know how swcs work in great detail, but including the custom base classes doesn't really matter, if it even includes them at all. In flash pro, add your src folder to the project classpath to have access to the files.

That's probably how I'll end up doing things, since I'm not motivated enough to make a complete level editor, haha. The reason I asked all this in the first place is because I do have my code in a src folder included in the main file, however when I tried to add my class to the base class in my SWC, it yelled at me with an error.

Thank you for helping me out! I really appreciate it


BBS Signature

Response to Big Artwork In Swc 2013-10-29 20:20:53


At 10/29/13 08:12 PM, coln wrote: That's probably how I'll end up doing things, since I'm not motivated enough to make a complete level editor, haha.

Flash pro is your level editor.