i'm using a 2D vector class to represent a position. one position instance is shared by some other class instances (sprite, mover). one of the class setfs the position, which creates a new instance however and sprite and mover refer to the old instance. is their a setf or something which only copies the values thus all the other classes have the updated position state? sorry for the newbish question...
the copy functions create new instances as well.
edit: something like replace which also works on structures.
the copy functions create new instances as well.
edit: something like replace which also works on structures.
(defclass vec ()
((x :initarg :x :accessor x-of)
(y :initarg :y :accessor y-of)))
(defmethod vec+ ((vec1 vec) (vec2 vec1))
(make-instance 'vec
:x (+ (vec-x vec1) (vec-x vec2))
:y (+ (vec-y vec1) (vec-y vec2))))
(setf position (vec+ position offset))Last edited by hewih on , edited 6 times in total.