Skip to content

Commit 270ed6b

Browse files
betpowoRaltyro
andauthored
Note.noteAngle rewrite, fixes minus scrollSpeed (#857)
* fix 90% of issues with noteAngle and scrollSpeed of notes cool , sustains now dont look like ass when rotated and negative scroll speed doesnt mess tem up anymore although the consequence of this is that noteAngle will go the other way around if on downscroll but i cant rlly get myself to fix that ;-; * downscroll is done (hopefully --------- Co-authored-by: Ralty <78720179+Raltyro@users.noreply.github.com>
1 parent 39968ef commit 270ed6b

2 files changed

Lines changed: 42 additions & 59 deletions

File tree

source/funkin/game/Note.hx

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package funkin.game;
22

33
import flixel.math.FlxPoint;
4+
import flixel.math.FlxAngle;
45
import flixel.math.FlxRect;
56
import funkin.backend.chart.ChartData;
67
import funkin.backend.scripting.events.note.NoteCreationEvent;
@@ -243,10 +244,14 @@ class Note extends FlxSprite
243244
override function drawComplex(camera:FlxCamera) {
244245
var downscrollCam = (camera is HudCamera ? ({var _:HudCamera=cast camera;_;}).downscroll : false);
245246
if (updateFlipY) flipY = (isSustainNote && flipSustain) && (downscrollCam != (__strum != null && __strum.getScrollSpeed(this) < 0));
246-
if (downscrollCam) {
247-
frameOffset.y += __notePosFrameOffset.y * 2;
247+
if (downscrollCam && __strum != null) {
248+
final xx = x;
249+
x += origin.x - offset.x;
250+
x -= __strum.x; x *= -1; x += __strum.x;
251+
x -= origin.x - offset.x;
252+
x += __strum.width; // ??? maybe this isnt good
248253
super.drawComplex(camera);
249-
frameOffset.y -= __notePosFrameOffset.y * 2;
254+
x = xx;
250255
} else
251256
super.drawComplex(camera);
252257
}
@@ -258,36 +263,24 @@ class Note extends FlxSprite
258263
@:privateAccess var oldDefaultCameras = FlxCamera._defaultCameras;
259264
@:privateAccess if (__strumCameras != null) FlxCamera._defaultCameras = __strumCameras;
260265

261-
var negativeScroll = isSustainNote && nextSustain != null && lastScrollSpeed < 0;
262-
if (negativeScroll) offset.y *= -1;
263-
266+
var negativeScroll = isSustainNote && strumRelativePos && lastScrollSpeed < 0;
267+
if (negativeScroll) y -= height;
264268
if (__strum != null && strumRelativePos) {
265-
var pos = __posPoint.set(x, y);
266-
267-
setPosition(__strum.x, __strum.y);
268-
269-
__notePosFrameOffset.set(pos.x / scale.x, pos.y / scale.y);
270-
271-
frameOffset.x -= __notePosFrameOffset.x;
272-
frameOffset.y -= __notePosFrameOffset.y;
273-
274-
this.frameOffsetAngle = __noteAngle;
275-
269+
final pos = __posPoint.set(x, y);
270+
// distance = pos.y , we can use it safely like this
271+
final xx = -origin.x + offset.x + (pos.y * Math.cos((__noteAngle + 90) * FlxAngle.TO_RAD));
272+
final yy = -origin.y + offset.y + (pos.y * Math.sin((__noteAngle + 90) * FlxAngle.TO_RAD));
273+
setPosition(
274+
xx + __strum.x + (__strum.width * 0.5),
275+
yy + __strum.y + (__strum.height * 0.5)
276+
);
276277
super.draw();
277-
278-
this.frameOffsetAngle = 0;
279-
280-
frameOffset.x += __notePosFrameOffset.x;
281-
frameOffset.y += __notePosFrameOffset.y;
282-
283278
setPosition(pos.x, pos.y);
284-
//pos.put();
285279
} else {
286-
__notePosFrameOffset.set(0, 0);
287280
super.draw();
288281
}
282+
if (negativeScroll) y += height;
289283

290-
if (negativeScroll) offset.y *= -1;
291284
@:privateAccess FlxCamera._defaultCameras = oldDefaultCameras;
292285
}
293286

@@ -301,7 +294,7 @@ class Note extends FlxSprite
301294
if (lastScrollSpeed != scrollSpeed) {
302295
lastScrollSpeed = scrollSpeed;
303296
if (nextSustain != null) {
304-
scale.y = (sustainLength * 0.45 * scrollSpeed) / frameHeight;
297+
scale.y = (sustainLength * 0.45 * Math.abs(scrollSpeed)) / frameHeight;
305298
updateHitbox();
306299
scale.y += gapFix / frameHeight;
307300
}
@@ -311,7 +304,7 @@ class Note extends FlxSprite
311304
}
312305

313306
public function updateSustainClip() if (wasGoodHit && !noSustainClip) {
314-
var t = CoolUtil.bound((Conductor.songPosition - strumTime) / height * 0.45 * lastScrollSpeed, 0, 1);
307+
var t = CoolUtil.bound((Conductor.songPosition - strumTime) / height * 0.45 * Math.abs(lastScrollSpeed), 0, 1);
315308
var rect = clipRect == null ? FlxRect.get() : clipRect;
316309
clipRect = rect.set(0, frameHeight * t, frameWidth, frameHeight * (1 - t));
317310
}

source/funkin/game/Strum.hx

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package funkin.game;
22

33
import flixel.math.FlxPoint;
4+
import flixel.math.FlxAngle;
45
import funkin.backend.system.Conductor;
56

67
class Strum extends FlxSprite {
@@ -162,41 +163,30 @@ class Strum extends FlxSprite {
162163

163164
if (shouldX || shouldY) {
164165
if (daNote.strumRelativePos) {
165-
if (shouldX) daNote.x = (this.width - daNote.width) * 0.5;
166+
if (shouldX) daNote.x = 0;
166167
if (shouldY) {
167-
daNote.y = (daNote.strumTime - Conductor.songPosition) * (0.45 * getScrollSpeed(daNote));
168-
if (daNote.isSustainNote) daNote.y += height * 0.5;
168+
daNote.y = ((daNote.strumTime - Conductor.songPosition) * 0.45 * getScrollSpeed(daNote));
169+
if (daNote.isSustainNote) daNote.y += daNote.height * 0.5;
169170
}
170171
} else {
171-
var offset = FlxPoint.get(0, (Conductor.songPosition - daNote.strumTime) * (0.45 * getScrollSpeed(daNote)));
172-
var realOffset = FlxPoint.get(0, 0);
173-
174-
if (daNote.isSustainNote) offset.y -= height * 0.5;
175-
176-
if (Std.int(daNote.__noteAngle % 360) != 0) {
177-
var noteAngle = FlxMath.fastSinCos(daNote.__noteAngle / PIX180);
178-
var noteAngleCos = noteAngle.cos;
179-
var noteAngleSin = noteAngle.sin;
180-
181-
var aOffset:FlxPoint = FlxPoint.get(
182-
(daNote.origin.x / daNote.scale.x) - daNote.offset.x,
183-
(daNote.origin.y / daNote.scale.y) - daNote.offset.y
184-
);
185-
realOffset.x = -aOffset.x + (noteAngleCos * (offset.x + aOffset.x)) + (noteAngleSin * (offset.y + aOffset.y));
186-
realOffset.y = -aOffset.y + (noteAngleSin * (offset.x + aOffset.x)) + (noteAngleCos * (offset.y + aOffset.y));
187-
188-
aOffset.put();
189-
} else {
190-
realOffset.x = offset.x;
191-
realOffset.y = offset.y;
172+
final speed = getScrollSpeed(daNote);
173+
final distance = (daNote.strumTime - Conductor.songPosition) * 0.45 * speed;
174+
final __noteAngle = FlxMath.fastSinCos((daNote.__noteAngle + 90) * FlxAngle.TO_RAD);
175+
final angleX = __noteAngle.cos;
176+
final angleY = __noteAngle.sin;
177+
final _noteOffset = FlxPoint.get(angleX * distance, angleY * distance);
178+
_noteOffset.x += -daNote.origin.x + daNote.offset.x;
179+
_noteOffset.y += -daNote.origin.y + daNote.offset.y;
180+
if (daNote.isSustainNote) {
181+
final m = (daNote.height * 0.5 * (speed < 0 ? -1 : 1)); // daNote.height works better than this.height in this case ???
182+
_noteOffset.x += angleX * m;
183+
_noteOffset.y += angleY * m;
192184
}
193-
realOffset.y *= -1;
194-
195-
if (shouldX) daNote.x = x + realOffset.x;
196-
if (shouldY) daNote.y = y + realOffset.y;
197-
198-
offset.put();
199-
realOffset.put();
185+
_noteOffset.x += x + (width * 0.5);
186+
_noteOffset.y += y + (height * 0.5);
187+
if (shouldX) daNote.x = _noteOffset.x;
188+
if (shouldY) daNote.y = _noteOffset.y;
189+
_noteOffset.put();
200190
}
201191
}
202192
}

0 commit comments

Comments
 (0)