Hi all,
I’ve got a menu class and selection works fine.
Strangly when running the game after several seconds it starts lagging like hell.
I’m cleaning and destroying the object.
the problem should be in here somewhere perhaps any of you can give a glance at it.
Thanks in advance,
Formatwizard
from pandac.PandaModules import *
from direct.showbase.DirectObject import DirectObject
from direct.gui.OnscreenImage import OnscreenImage
from direct.task.Task import Task
import time
class Menu(DirectObject):
def __init__(self):
wp = WindowProperties()
wp.setCursorHidden(True)
base.win.requestProperties(wp)
self.player1snd = loader.loadSfx("audio/fx/singleplayer.wav")
self.player2snd = loader.loadSfx("audio/fx/multiplayer.wav")
self.txture = loader.loadTexture("menu/bckgrnd.avi")
self.onePlayerImage = OnscreenImage("menu/1player.png", pos = Point3(-0.5, 0, 0), scale = Vec3( 0.18,0,0.3 ) )
self.onePlayerImage.setTransparency(TransparencyAttrib.MAlpha)
self.twoPlayerImage = OnscreenImage("menu/2players.png", pos = Point3(0.5, 0, 0), scale = 0.3 )
self.twoPlayerImage.setTransparency(TransparencyAttrib.MAlpha)
self.cursor = OnscreenImage("cursor/glove.png", pos = Point3(-1.25,0,0), scale = Vec3(0.08,0.1,0.08))
self.cursor.setTransparency(TransparencyAttrib.MAlpha)
self.p1Time = 0
self.p2Time = 0
self.txture.setLoop(False)
#CREATE CARDMAKER OBJECT IN cm VARIABLE
cm = CardMaker("");
cm.setFrameFullscreenQuad()
cm.setUvRange(self.txture)
#CREATE movieNode AND GENERATE CARDMAKER
self.mNode = NodePath(cm.generate())
self.mNode.reparentTo(render2d)
#SET TEXTURE TO MOVIENODE (MOVIE)
self.mNode.setTexture(self.txture)
self.snd = loader.loadSfx("audio/fx/cargoby.wav")
#SYNC SOUND TO MOVIEFILE
#self.snd.play()
def mouseEvent(self, task):
if base.mouseWatcherNode.hasMouse():
x=base.mouseWatcherNode.getMouseX()
y=base.mouseWatcherNode.getMouseY()
self.cursor.setPos( x, 0 , y )
if ( (x >= -0.5699) and (x <= -0.3549) and (y >= -0.3166) and (y <= 0.1733) ):
if ( self.p1Time != 1) and (self.player1snd.status() -1 == 0):
self.player1snd.play()
self.p1Time = 1
self.p2Time = 0
if ( base.mouseWatcherNode.isButtonDown( MouseButton.one( ) ) ):
self.setChoice("singlePlayer")
self.destroy()
return task.done
elif ( (x >= 0.2800) and (x <= 0.8100) and (y >= -0.3166) and (y <= 0.1733) ):
if ( self.p2Time != 1) and (self.player2snd.status() -1 == 0):
self.player2snd.play()
self.p2Time = 1
self.p1Time = 0
if ( base.mouseWatcherNode.isButtonDown( MouseButton.one( ) ) ):
self.setChoice("multiPlayer")
self.destroy()
return task.done
return task.cont
def setChoice(self, choice):
self.choice = choice
def getChoice(self):
return self.choice
def destroy(self):
self.mNode.remove()
self.txture.stop()
self.onePlayerImage.destroy()
self.twoPlayerImage.destroy()
self.cursor.destroy()
self.player1snd.stop()
self.player2snd.stop()
self.snd.stop()
self.ignoreAll()