English 中文(简体)
我的“最后PVECtor”变量 正在改变每个框架,为什么?
原标题:My "final PVector" variable is changing every frame, why?
Every Frame, my particle system position changes, without me ever assigning to it. Like so: [50.821663, 49.430023] [51.553301, 50.059512] [52.480217, 47.301073] [53.643673, 48.139871] [55.829941, 50.354572] [58.192818, 51.504097] [57.826793, 52.627758] [54.456882, 52.148365] Anyway here s my (simplified) Particle class: class Particle { PVector pos = new PVector(); void Display() { pos.add(PVector.random2D().limit(7)); } Particle(PVector pos) { this.pos = pos; } } And the ParticleSystem: class PartSys { final PVector Pos = new PVector(50,50); ArrayList Particles = new ArrayList(); void run() { circle(Pos.x,Pos.y,100); for(Particle part : Particles){ part.Display(); } } } ParticleSys.run(); is ran every frame.
最佳回答
My trouble came from this line: this.pos = pos; When I set the position in the constructor function, it set this.pos as a reference to our ParticleSystem position. You see, on this line pos.add(PVector.random2D().limit(7)); (Which seemed like a perfectly reasonable thing to do) I was indirectly (through this.pos) adding to the original ParticleSystem position. MASSIVE thanks to @xerx593
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签