Citrus-Engine
Citrus-Engine copied to clipboard
Curious about CitrusObject.as, whether it may be a little too light? here's why-
Just a thought.. let's take a physics engine object and a citrussprite for example, if these two were stored in the same array, how would one access the x and y values via array[ i ].x/y? If the only common parent is CitrusObject.
if these two were stored in the same array, how would one access the x and y values via array[ i ].x/y?
Just by making a cast? (myArray[0] as CitrusSprite).x
Also, to do it properly, we should cast using the interface ISpriteView
. But it seems that APhysicsObject
doesn't implement it. Any idea @gsynuh why it hasn't been done?
If I were to write that, and there was a nape physics object in the array, wouldn't it error? ( cycling through the array via for loop )
If your myArray[0]
object was a Nape object, yes. The issue you're right, is that CitrusSprite
& APhysicsObject
just have CitrusObject
as the parent. We should put the interface for both of them.
Well, in fact NapePhysicsObject
already implements ISpriteView
so everything works as expected!
Just use myArray[0] as ISpriteView).x
and no matter if its a CitrusSprite
or a NapePhysicsObject
.
Ah, alright, damn, I did not know I could use interface classes like that, I was always taught they were just to enforce a different class to follow that blueprint (interface) nothing more. Thank you
can the common properties in the interface class be set? As in: (myArray[0] as ISpriteView).visible = false , as there are no setter functions, thanks for your time.
yes visible can be set.
actionscript interfaces does not allow us to force anything other than methods, so to say that any ISpriteView object should have a "visible" property, we define the getter as a workaround. So at least its going to be a readable property but in reality they can be set as well (edit: you can see "view" is in there as well)
Come to think of it, I'd totally understand if this line threw an error because there's no explicit set defined in the interface - and in that case we'd have to add it