Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curious about CitrusObject.as, whether it may be a little too light? here's why- #251

Open
Snky opened this issue Mar 6, 2015 · 8 comments

Comments

@Snky
Copy link

Snky commented Mar 6, 2015

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.

@alamboley
Copy link
Member

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 APhysicsObjectdoesn't implement it. Any idea @gsynuh why it hasn't been done?

@Snky
Copy link
Author

Snky commented Mar 6, 2015

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 )

@alamboley
Copy link
Member

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.

@alamboley
Copy link
Member

Well, in fact NapePhysicsObject already implements ISpriteViewso everything works as expected!

Just use myArray[0] as ISpriteView).x and no matter if its a CitrusSprite or a NapePhysicsObject.

@Snky
Copy link
Author

Snky commented Mar 6, 2015

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

@Snky
Copy link
Author

Snky commented Mar 6, 2015

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.

@gsynuh
Copy link
Member

gsynuh commented Mar 6, 2015

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)

@gsynuh
Copy link
Member

gsynuh commented Mar 6, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants