0 Members and 1 Guest are viewing this topic.
This is a drawback of the differences between C++ and C#, and me not being an expert in the latter The Transform property of a sprite is a read-only attribute, you can't change it like this.The correct code is:sprite.Rotate(i);sprite.Scale(i, i);
Oh. Could you make the Transform.Rotate(), Transform.Translate() methods private? It's counter-intuitive to have them accessible by the user.
QuoteOh. Could you make the Transform.Rotate(), Transform.Translate() methods private? It's counter-intuitive to have them accessible by the user.No, they are usable if you have a custom Transform instance. What should be done here is that Sprite.Transform should return a const/read-only object -- but that's not possible in C#, right?
No, there's no way of doing this. For instance, if you return a List<string> (and it's not immutable) then callers will be able to add entries.The normal way round this is to return an immutable wrapper, e.g. ReadOnlyCollection<T>.For other mutable types, you may need to clone the value before returning it.Note that just returning an immutable interface view (e.g. returning IEnumerable<T> instead of List<T>) won't stop a caller from casting back to the mutable type and mutating.EDIT: Note that apart from anything else, this kind of concern is one of the reasons why immutable types make it easier to reason about code
0 is ignored as a scale factor.