Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Joystick vs Background Music
#1
Hi Marcus,

In the Space Pooper (N7 version) that I am currently working on, I’ve run into something that I can’t seem to resolve 'Joystick problem' by myself.

My joystick responds correctly when this part of the background music code is not included. I believe I may be doing something wrong in my coding.

Code:
' Background music
'title = loadmusic("assets/title.mp3")
'play music title, true

If you have some free time when you’re not at work, would you mind taking a look at my code? Please don’t worry about it—it’s not urgent at all.

Thank you very much in advance for your time and help.

Code:
'===================================
' Joystick Demo
' - stage 2
' - joystick support (LEFT, RIGHT)
'===================================

include "tilemap.n7"

#win32
set window "Joystick Demo", 256, 240, false, 2
set redraw off
randomize time()

' Variables
visible player = []
visible scrollY , scrollTimer 'scrolling tilemap
visible title

' Background music
'title = loadmusic("assets/title.mp3")
'play music title, true

' Init Player
player.img = loadimage("assets/player.png") ;set image colorkey player.img, 255, 0, 255 ; set image grid player.img, 2, 1
player.x = (width() / 2) - (width(player.img) / 2)
player.y = 180
player.dx = 0
player.cel = 0
player.tickCounter = 0

' Init Tilemap
ResetTilemap()


'------------
' Main Loop
'------------
while not keydown(KEY_ESCAPE, true)
    ' Tilemap vertical scrolling
    scrollTimer = (scrollTimer + 1) % 4
    if scrollTimer = 0 then
        scrollY = scrollY - 1
    endif

    ' Keyboard & Joystick Input
    if keydown(KEY_LEFT)  player.dx = player.dx - 0.4
    if keydown(KEY_RIGHT) player.dx = player.dx + 0.4
    player.dx = player.dx + joyx() * 0.4
   
    player.dx = player.dx * 0.9
    player.x = player.x + player.dx

    ' Boundaries
    if player.x < 0 then player.x = 0
    if player.x + width(player.img) > width() then player.x = width() - width(player.img)

    ' Player Animation
    player.tickCounter = (player.tickCounter + 1) % 8
    if player.tickCounter = 0 then player.cel = 1 - player.cel

    ' Clear screen
    set color 0, 0, 0 ; cls ; set color 255, 255, 255
   
    ' Tilemap camera
    TM_SetCamera(int(player.x) * 32 / width(), scrollY)
    TM_Render()

    ' Draw Player
    draw image player.img, player.x, player.y, player.cel

    ' Draw Heads-Up-Display
    set caret width() / 2, 4 ; center "SCORE"
    set justification left ; set caret 4, 4 ; wln "SHIPS"
    set justification right ;set caret width() - 4, 4; wln "STAGE" ; wln "2"

    redraw
    fwait 60
wend


'------------
' Functions
'------------
function ResetTilemap()
    if TM_LoadMap("assets/2.txt") = 0 then end
    scrollY = TM_MapHeight() * 16 - height()
    scrollTimer = 0
    TM_SetView(0, 0, width(), height())
    TM_SetCamera(16, scrollY)
endfunc


Attached Files
.zip   joystick_test.zip (Size: 422.15 KB / Downloads: 2)
Reply
#2
I read your problem and immediately dusted off the old joystick...

I do not run N7 natively on my Linux Mint machine, I run it using the application Wine.

I have tested the joystick with Linux and Wine and the stick functions just fine.
Fired up you joystick test program, made sure the music was set to play.... Voila! Movement and music worked perfectly.

I have a fire button just itching to shoot aliens!!! Moo Ha Ha Ha...
Logic is the beginning of wisdom.

Live long and prosper.
Reply
#3
We've stumbled upon this before, hm, and I couldn't quite figure out why it didn't work (music + joystick works fine on my system). The joystick stuff probably needs a re-work, and I have also planned to add some things for music and sound.

... I have a vague memory of a hack solving it. What happens if you load the music before calling "set window"?

Edit: https://www.naalaa.com/forum/thread-299.html I will try and solve the issue of course, but does the hack still work?
Reply
#4
(08-25-2026, 06:40 AM)Marcus Wrote: We've stumbled upon this before, hm, and I couldn't quite figure out why it didn't work (music + joystick works fine on my system). The joystick stuff probably needs a re-work, and I have also planned to add some things for music and sound.

... I have a vague memory of a hack solving it. What happens if you load the music before calling "set window"?

Edit: https://www.naalaa.com/forum/thread-299.html  I will try and solve the issue of course, but does the hack still work?

The hack still works !  Big Grin Big Grin Big Grin
Thank you, now I am continuing The Space Pooper (N7) conversion project
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)