So I have 20 variables named fact[x] where x is from 0 to 19. I have this command under the Left_Released in an object called randomf:
if instance_exists(facts) {
with facts {instance_destroy()}
}
instance_create(x,1395,facts)
facts (object) has this code under draw:
draw_set_font(FedraS)
draw_set_colour(c_white)
draw_set_halign(fa_center)
draw_text_ext(room_width/2,y,randomf.fact[irandom(19)],48,room_width-32)
What is happening is that whenever I'm clicking on the object, it draw a random fact and then deletes it and then draws the next fact endlessly. Where am I going wrong?
thanks.
Okay I solved it, apparently the Draw function is called every step and not just once. I just used a variable called cast = irandom(19).
Related
So basically I have two questions. I am also copying off this video from 2014: https://www.youtube.com/watch?v=w8JgpEjm8i8&t=2792s
Question 1
At the end of the video above the guys computer completely crashed and he wasnt able to show the end of how to setup a death animation for my player (link). So currently I have setup a movie clip of the death animation - just the playing spinning around - and put it in another movie clip called 'All Sprites' in which I have my other movie clips such as the different walking directions. So I have placed it in there, labelled it with "Link Death Frame". I then went back to the main script and added code so that once my player dies, the animation will play. Such as:
~
if(linkHealthBarMC.scaleX <= 0.01)
{
linkAlive = false;
}
trace(linkAlive);
if(linkAlive == false)
{
linkMC.gotoAndStop("Link Death Frame");
}
~
However, the issue comes in which the animation doesnt actually play, it just goes straight to the first frame and doesnt play. I have tested it and I know for sure that it gets stuck on the first frame and that something must be wrong with the animation as I tested it with another animation and it worked fine (once I met the requirements for the animation to play). So does anyone have any idea how I can fix this issue so that my character can play a death animation?
Question 2
How do I stop time? Like just completely freeze everything after my character is dead? Because at the moment I am just going to the first frame of the death animation and can still move and attack.
I'd assume this is on an EnterFrame loop. Then you would have two possible causes for this:
1.) You're loop is constantly checking if the 'linkAlive' if statement is false (which it is) and setting your Animation to the first frame. You can check this method by putting a Trace statement in your if statement and if the output window overflows, then that's your culprit.
2.) What you want is gotoAndPlay(-insert label here-)
Tho it is outside the scope of the question you have, I create a variable~Switch State machine to control states for me:
1.) Current State as a number (int, number, or uint)
2.) function with a switch statement (Switch is kind of a fancy if Statement)
3.) inside the cases are instructions
switch(current_state){
case 1:
linkMC.gotoAndPlay('death animation');
break;
}
if (current_state != 1){
-put movement code here-
}
This is close to what I use for my game. Just checking states or you can have a variable like the one above that explicitly checks for the death state and remove the ability to move. If you use a mouse (and I assume event listener) then you can remove the event listener for the mouse. If you use a solution like keyboard inputs then an if statement would be more what you are looking for.
I'm developing my first game and I have a player class (FlxSprite) that has a death animation.
I want to remove the player from the stage as soon as the animation ends, but if I use:
player.animation.play('death');
remove(player);
The animation doesn't finish and the player just disappears.
The way I handle this in most of my projects is something like this:
override public function update(elapsed:Float):Void
{
if (!alive)
{
if (animation.finished)
{
exists = false;
}
super.update(elapsed);
}
// other update stuff...
super.update(elapsed);
}
override public function kill():Void
{
if (!alive || !exists)
{
return;
}
alive = false;
animation.play("death", true);
// Note: I DO NOT call super.kill() because I want to leave exists = true
}
And, in your PlayState or wherever you want to remove the object, just check if (!player.exists) remove(player);, I guess? I don't usually use remove, I just wait until the state is destroyed and then clean everything up with FlxDestroyUtil.
Your question isn't super clear, but I'll try help anyway.
Because of the way the game loop is looping, the remove function kills off the sprite before the animation plays. You can check to see when the animation is finished by putting an if statment in your update function, like so.
if (animation.finished) kill()
If you need an actual timed delay, you can see my previous answer where you increase a variable by FlxG.elapsed every update on a variable until it exceeds your timer length.
I hope this answers your question. You may want too look at methods such as kill() in the HaxeFlixel docs, as I think you might be confused with remove().
EDIT: very sorry, forgot to include one important detail. It is likely that you are calling animation.play every single frame - stop once your death animation plays. In my code I saw I have an isDying variable that stops any new animations starting, and checks to see if the current animation is finished. Without this, the finished variable might not flip.
I am currently making a game and need the score to get updated in while loop.
Every time the score gets updated in figure, it overwrites on top of previously written text making it blur.
The code goes something like this:
score=score+100
text(90,105,num2str(score));
h=text(80,105,'SUN');
set(h,'color','r');
You should keep the handle of the original text box, then update its 'String' property. Instead you keep creating a new text box on top of the old one.
Don't have access to matlab right now but I think something like this should work:
% first time you report score! create a text object; call it's handle "scoreBoard"
scoreBoard = text(x,y,num2str(score));
% something happens and we have new score:
set(scoreBoard, 'String', num2txt(score)); % update the string property of scoreBoard
Alternatively you could delete the old object and create a new one. I suspect the method I gave above is slightly more efficient though.
I am learning PyQt4 (I am using version 4.4.4) and I'm pretty new to Python (Python 2.5). I have a GUI with a QListWidget and a QPushButton. I want a user to be able to click to select an entry in the list and then click the QPushButton and have the selected entry go away (be deleted from the QList). I've been banging my head against this problem for over a week and I would deeply appreciate some help.
Currently, my GUI comes up and I can select different list items (only one at a time right now), but when I click the QPushButton, nothing happens. The selection color goes from blue to grey, but the entry is not removed. No error is shown in Command Prompt (Windows 7).
I have defined a function, remove(),which I am using as the slot for the QPushButton. I believe the QPushButton.connect is defined correctly for a Qt Signal to Python Slot, based on what I've seen of answers to similar problems, but the items are not being deleted. However, the remove function is not even being triggered. I have a print statement within the function, but it is not being called when I click the QPushButton, which is how I know that the function is not being called.
Here is my most recent code: (I read a very rant-y post on meta-SO about big blocks of code, so I've cut this down to the bits I think are relevant: the list creation, the button creation and the remove function, which I'm trying to use as a slot. I've left in comments that indicate what the other sections are, so if you think I've left out something that could help, let me know and I'll add it back in)
class questionGUI(QtGui.QWidget):
#This class is the window of the gui.
def __init__(self):
super(questionGUI,self).__init__()
#Layout
grid = QtGui.QGridLayout()
grid.setSpacing(10)
#Labels Needed
...
#Question List
self.qList = QtGui.QListWidget()
#print self.qList
self.qList.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
entries = ['[Pick Image] <Default>','[Slider Question] <Default>', '[Comment Box] <Default>']
for i in entries:
item = QtGui.QListWidgetItem(i)
self.qList.addItem(item)
#Type select
...
#Text insert Needed
...
#Buttons Needed
deleteButton = QtGui.QPushButton('Delete Question')
deleteButton.connect(deleteButton,QtCore.SIGNAL('itemClicked(clicked)'),lambda: self.remove)
addQuestionButton = QtGui.QPushButton('Add Question')
...
doneButton = QtGui.QPushButton('Done')
...
#Parameters Needed
...
#Layout Placement and Window dimensions
...
def addQuestion(self):
...
def remove(self):
print 'remove triggered'
print self.qList.currentItem()
self.qList.removeItemWidget(self.qList.currentItem())
...
I tried to post an image, but I don't have enough reputation. If you think an image would be useful, let me know and I can send it to you.
You mixed the signals:
deleteButton.connect(deleteButton,QtCore.SIGNAL('itemClicked(clicked)'),lambda: self.remove)
deleteButton is a QPushButton, but itemClicked(clicked) looks like the signal from QListWidget with wrong signature. Since, QPushButton doesn't have this signal, no connection is made. Qt doesn't raise errors for failed connections, but .connect method has a bool return value indicating success/failure of the attempted connection.
Also, lambda: self.remove as a slot doesn't make sense. Slot should be a callable that is called upon signal emit. Sure, lambda creates a function, but all you do is reference the method self.remove. lambda will be called, self.remove not. Just self.remove as a slot is enough.
You should use clicked() signal (or clicked(bool), if you care about the checked value) from button:
deleteButton.connect(deleteButton, QtCore.SIGNAL('clicked()'), self.remove)
Edit
Another problem: Your remove method doesn't do what you want. removeItemWidget doesn't remove the item, it removes the widget inside the item (if you set one). It's counterpart to setItemWidget.
You should use takeItem to remove items.
def remove(self):
self.qList.takeItem(self.qList.currentRow())
I am using a while loop and within that I add ginput in MATLAB to capture the positions of mouse. I check every time if the returned position is within some area so I will plot some curve on the current figure. But the problem is, by using ginput, I have to press enter before the positions are returned. Is that any way to capture the mouse event such that when the current cursor hover over some points, a callback function will be triggered? Thanks.
Since you already have a figure you're using, you could set the listening property for the figure:
set(gcf,'WindowButtonMotionFcn', #mouseMoveListener);
But now you have to create a function called 'mouseMoveListener' (if you want to name it something else, change the words after the # sign to whatever name you want, and make sure the actual event function is named that too).
Within your function mouseMoveListener you can now get the mouse coordinates:
MousePos = get(mainAxis,'CurrentPoint');
Which tells the current point of the mouse with respect to the axes coordinates. From there, you can have whatever if statement check that the position is where you want it and perform whatever tasks you want based on that information.