|
-
[CS3] Isometric game: object visibility
Hi scripters,
I am programming my own isometric game (AS3) with dynamic objects (with own 3d engine, editor etc etc).
Objects use 2d image what will be transformed to the proper perspective.
(klik on image for bigger sample).
To keep it all fast en lightweight i build all objects when entering the area (because when playing flash got enough other things to work on).
I have made a function what checks if objects are hitting the visible area(white lines rectangle).
If a object does not hit the visible area i set the object visibility FALSE else if he hits it is set to TRUE (because its within the visible area.
Now my question is: Are invisible objects use cpu power? (the x and y will always be updated even if the object is invisible).
EDIT: or should it do removeChild and addChild for setting it visible or not? (i guess adding and removing is slower as using visible true or false)
regards,
MasterX
Last edited by Master_X; 01-11-2009 at 01:55 PM.
-
its defenitly faster if you dont have them at all,- even more if you use movieClip containers or sprites as booth have events running even though you did not added ones yourself.
I am working atm. on a engine as well that has a similar projection like in your screenshot and render each cell with the drawing API (e.g canvas.graphics.beginBitmapFill(texture,matrix,... ); ) and since all objects get drawn per frame drawing as less cells and sprites as possible is important.
So per frame I check (screen clipping)
1.) which objects are visible in the viewport
2.) which faces of the objects are visible in the viewport (screen clipping)
after that I render them- meaning I use the drawing api to draw them.
another fast way is to use copyPixels if you use static 2d tiles . you say
transformed to the proper perspective
but even with that you could cache them as bitmaps and copyPixel them into a canvas bitmap. This is supposed to be very fast as the copyPixels command is lighting fast. Even in this scenario you would have to check wich cells to render on the screen so copyPixel them and thus finally render only what you need- no visible swapping.
I would say that with AS3 movieClips are not really that fast- that would be just like working with AS1 or AS2 - using sprites, bitmapData or the drawing API is the key to performance - a smart engine that calculates whats visible (viewport clipping, or camera clipping) makes sure that only a smal amount of the whole world needs to be rendered.
the screenshot looks promosing,- will follow this
-
reply
dear renderhjs,
I am also using the drawing API.
- Got for example Cube class ( public function Cube(x:Number,y:Number,z:Number, sizeX:Number,sizeY:Number,sizeZ:Number, sidesMaterials:Object=null, rotationStep:uint=0) )
- That Cube class generates from every given sideMaterial a face (flat rectangle) what will be transformed with a matrix to the right perspective).
I also still have to check what faces are visible (for now just turned off all bottom, back and right faces)
I also do cacheasbitmap with all objects (that really did a preformance boost)
I also use sprites instead of movieclips (never used movieclips ever because i started with as3 using flexbuilder)
As you can see on the screenshot only the needed floortiles are visible
Only for the objects i draw them all and then calculate if they need to be visible or not.
So you suggest not to use visible or not visible but deleting entire object(s) and redraw the entire objects (when needed).
I have also tried copyPixels for updating the player sprite but it was slower as:
this.graphics.clear();
this.graphics.beginBitmapFill(this.global.imgMgr.p layer[spriteCounter]);
this.graphics.drawRect(0,0, 80, 120);
this.graphics.endFill();
(probably because i didnt use it proper or something)
regards,
MasterX
PS: the character is from the ffanimation engine and the fase textures ripped from google (just using it for testing because i am not a designer and defo not a 3d animator ) offcourse i will buy my own if game goes alpha or higher
-
you can use the Shape container if you want the fastest container its usefull if you dont need mouse Events for example for that container. I use the shape container often for 3d rendering.
from heavy to light:
MovieClip > Sprite > Shape
sprite is the fastest that still accepts mouse events - but like I said if its just for visual data better use Shape.
About clearing...if you already use:
PHP Code:
this.graphics.clear();
this.graphics.beginBitmapFill(this.global.imgMgr.p layer[spriteCounter]);
this.graphics.drawRect(0,0, 80, 120);
this.graphics.endFill();
it means that you clear the graphics container anyway - why not drawing then all of those "this." containers into 1 big container like:
PHP Code:
var g:Graphics = this.graphics;
var cells:Array = [....holds the cells information....];
cells.sortOn("y");
g.clear();
for (var i:int=0;i<cells.length;i++){
g.beginBitmapFill(cells[i].global.imgMgr.player[cells[i].spriteCounter]);
g.drawRect(0,0, 80, 120);
g.endFill();
}
cells.sortOn("y"); sorts the sprites based on their y-position assuming that the cells array is the one holding either objects or classes with y- properties of the positions. For a propper sorting assign each tile its depth value ahead and the sort it here. Not sure how you sort now as there are multiple ways of doing.
 Originally Posted by masterX
PS: the character is from the ffanimation engine and the fase textures
I noticed that right away- but even texturing might be interesting from the perspective of someone who writes a engine- like what about shadow casting, faking texture baking ect. dont think that strictly in categories -thats what so many people already do
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|