How to add next and previous buttons in matlab? - arrays

We create a matlab gui for registration.In that form we have to see each images from an array on the buttons clicks. we need to be implement two pushbuttons ie 'next' and 'previous'. when we click previous we have to see previous image on the axis and vice versa. plz help us. Thank you in advance.

Well, the steps are pretty straightforward:
In your GUI's OpeningFcn you should add code to load the images from the folder:
create a cell array filed in handles, e.g. handles.img_store;
load images one by one in handles.img_store{:} using imread();
create a current image index, e.g. handles.img_index, and initialize it to 1;
display the current image using display_current_image() function—see 4.;
Write the callback for the pushbutton "Next" to increment handles.img_index, reset it to previous value if it goes out of bounds of handles.img_store, then call display_current_image()—see 4.;
Write the callback for the pushbutton "Previous" to decrement handles.img_index, reset it to previous value if it goes out of bounds of handles.img_store, then call display_current_image() function—see 4.;
Create a function, e.g. display_current_image() that will take handles as argument and, using the image() function, displays the image with the index handles.img_index in the cell array handles.img_store
I will not write code, not until you try to write some code first. :-)

Related

Adding a new Entry in a Struct holding a TArray as Member value doesn’t update it’s entries

I am currently working on a Character Customization System where a HUDLayout dynamically create Widgets based on a set of Skins available for the Character Selected. A Skin is represented as a Struct called MaterialInstanceContainer and holds a TArray. Player can mix and match their selection according to the Body Parts they select. In order to achieve the final result, I want to create a TMap<string, MaterialInstanceContainer> so that I can map each BodyParts available for selection with the individual material instance targeting the same BodyPart.
ISSUE: My issue is as follow, when I try to foreach over my collection of Material Instances inside my Container, I do a string comparison and if the output is valid, I can then break my struct to access the Material Instance Array and ADD to it however, at the very end of the process, the length of the array inside Material Container is still at zero.
How can I add a new entry in the array that my Material Container Struct hold?
Thanks!
enter image description here
The issue here is actually pretty straight forward: in Blueprints when you 'Find' a member of Map you are not getting it by-reference, instead you get the copy.
This is exactly what happens at the end of your nested loop: You get a copy, you add item to it, and when another iteration kicks-in the copy gets terminated.
And here on my side it returns exactly the same result as expected:
The fix for that would be easy:
After editing a Copy, you can overwrite the Map member by its copy (via 'Add' node).
But in your case it will be more tricky. You cannot just plug the same BreakStruct/Array node that you just used because it would call whole Find sequence again which creates another copy. Look
If you are confused. This code actually looks like this for Unreal's point of view.
So you have to store the the Struct in local variable first, then perform any operations on it and after everything is done - overwrite the Map member by its locally stored copy. And the result is
Map member gets overwritten every time and everything is as it should be.
Well, almost... For some reason your code is stored in Macro. I think you have to change it to a Function to be able to create local struct variable. But it shouldn't be a problem in this specific case because in your code there is no logic that needs to be done in macro.
Hope, it helps

How to Loop a script in gamemaker

cantSee = collision_line(x,y,obj_player.x,obj_player.y,obj_corner,false,true)
canSee = !(collision_line(x,y,obj_player.x,obj_player.y,obj_corner,false,true))
Define the loop as the following:
if cantSee {
cantSeeTimer = cantSeeTimer +1
}
if cantSeeTimer >60 {
speed=0
stopped=true
} else {
mp_potential_step(obj_player.x,obj_player.y,5,false)
}
}
if stopped=true && canSee {
mp_potential_step(obj_player.x,obj_player.y,5,false)
loop()
}
I know the language is bad, but I just want to create a loop command to summon at will.
Thanks, Finn.
so you haven't specified which object in your game currently has this code but it shouldn't matter too much.
So in Game Maker or Game Maker Studio there are a series of events an object can have and one of them is called a "Step" event. A step event is basically a loop that will cycle the amount of times the room speed is per second. Eg: If the room speed of a room is 30 the step event will loop 30 times per second.
I think I can see what you are trying to do and I think I have a solution for you.
Since you can write GML code I am going to assume you understand how to use the GMS or GM IDE.
We want to create a new object called obj_control (or you can choose a custom name). Also don't give this object a sprite as we don't want the player to see it.
Now we want to add an event to our new object so make sure you still have the windows for obj_control (or whatever u called it open). and click on the 'Add Event button' shown in this image: http://imgur.com/A7szwFO
Once you click on it, click on 'Step'. http://imgur.com/s0ksiyD
Now select 'Step' again. ('Begin Step' and 'End Step' don't do what we want so let's just ignore them)
Now we need to add your code to the step event we just created. So make sure you are on the 'Control' tab and find the script editor (you should know where to find it) and drag one into the 'Actions' for the step event.
http://imgur.com/de3gE01
Now a script editor should pop up automatically but if it doesn't just double click the "Execute piece of code". Now we just need to copy and paste all of your code into the script editor.
http://imgur.com/sNBOCFu
Now click on the green tick on the top left corner of the window to save the code.
Now before we are done let's make sure we define the variables in a create event. So make a create event and add this code:
cantSee = collision_line(x,y,obj_player.x,obj_player.y,obj_corner,false,true)
canSee = !(collision_line(x,y,obj_player.x,obj_player.y,obj_corner,false,true))
After you have added that create event and inserted that code into it save all changes to the object.
All that is left is to add this object we created to every room of the game so it can function.
Hopefully this helped and if it didn't just let me know and we can get it sorted.

ActionScript 2 - Get MovieClips' initial position and save it for each mc for later target position

I am working on an animation in AS2 which requires that all text MovieClips (instance names starting with "txt_") will be manually placed initially on stage and I need to store their own initial placed positions (x,y) so they will be retrievable later when I want to animate them to these same final coordinates regardless of where they move around in the meantime.
So the following steps needed:
All these text movieclips are placed on stage manually from library (not dynamically) matching their expected target keyframe end position (x,y) to get desired final screen layout.
Then a frame script loops through all these MovieClip instances on stage before rendering them on stage and stores their initial (also future target) (mc.targetPosX or mc.targetPosY) positions.
Then frame script also moves all of these MovieClip instances before rendering them on stage and moves/offsets them elsewhere on stage (eg. mc._x +=25px;) and hides them (eg. mc._alpha =0;)
Finally by using a tween like Greensock I want to use their stored target end position to animate each of them to their stored final target position.
(eg. TweenLite.to(mc, 1,{_alpha:100, _x:mc.targetPosX, ease:Quad.easeOut});)
I was able to create a loop to get "txt_" movieclips but then I don't know how to save their target positions with their instance and use them outside the loop afterwards.
Thank you in advance,
Attila
I don't know what problems do you have trying store some variables inside instances, but here my suggestions about proccess you described.
First of all we have loop which do all thing you described at question.
To do so we must have some list of you mc's or pattern to make this list dynamically. From you question i suppose that you use this kind of loop.
for(var i=0, txtCount=10; i<txtCount; i++){
textMc = this['txt_'+i];
//do stuff
...
}
From here on your points.
You already did it.
Use loop described above to store current object properties inside his instance
textMc.storedX=textMc._x;
textMc.storedY=textMc._y;
Here is same loop place object wherever you like
textMc._x+=25;
textMc._alpha=0;
Finally right after that in the same loop use greensock.
TweenLite.to(textMc, 1,{_alpha:100, _x:mc.storedX, ease:Quad.easeOut});
That's it.

LimeJS animation.Sequence does not complete

i have got a probling concerning my animation.Sqeuence.
Only the first Sequence Element is being executed. The 2nd is ignored.
I want the Sprite spell_1 to move to the Hero (hero_x_exact,hero_y_exact), and after that to the destination.
Each element works fine for itself but not in a Sequence.
goog.require('lime.animation.Sequence');
...
var spellmovement = new lime.animation.Sequence(
spell_1.runAction(new lime.animation.MoveTo(hero_x_exact,hero_y_exact).setDuration(1).enableOptimizations()),
spell_1.runAction(new lime.animation.MoveTo(target_coord_x_spell,target_coord_y_spell).setDuration(1).enableOptimizations())
);
What might work better is using a spritesheet with each animation on the spritesheet Then you can build something that loads each animation by name. Obj_Walk001.png, Obj_Walk002.png
Then create a method to read each animation per frame in the scheduling manager.
You can find an example of this code in limejs/lime/demos/test. Then goto run.htm and click on Frame4 this one will show you how limejs is going it.

Very Strange: Every other time an array is updated its values are screwed up

You can see the code there: http://jsfiddle.net/jocose/CkL5F/901/
(double click on the box and move your mouse)
NOTE: This is a simplified example that is part of a larger system. My ultimate goal is to manipulate individual vertices of a path.
Update: I crunched the numbers and the math actually apears to be correct. What I want to do is calculate the offset from each point to the mouse, and then move that point to the mouses position + the offset.
So if I have a mouse of 224 then 224-103 = 121 then I add: 121+224=345
These creates a cycle of ups and downs that I am seeing. I don't know why these is stumping me so badly, any help would be much appreciated.
I need to manually update a Raphael path element.
To do this I convert an absolute path into an array using Raphael great built in function "parsePathString"
I then loop through that array and modify the values based off the mouse position.
The update is done to the X values only, and is in real time; called each time the mouse moves.
When the element moves it flickers back and forth between the correct position and some anomalous one.
I have no clue why its doing this. I have spent almost 5 hours trying to figure this out and I'm officially stuck.
Here is a sample of the result where you can see the values jumping around:
MOUSE224
M,103.676287
MOUSE225
M,346.323713
MOUSE227
M,107.676287
MOUSE228
M,348.323713 12
MOUSE228
M,107.676287
MOUSE229
M,350.323713
MOUSE231
M,111.67S287
MOUSE232
M,3S2.323713
MOUSE233
M,113.676287
MOUSE233
M,3S2.323713
Here's my version of your fiddle modified to do what I think you need. At least, it seems to work. It's the same type of problem I had to fix for the Raphael 2 transformations here.
Basically, in your mousemove, I've changed mx to be a calculation of the offset between where your mouse is now and where it was the last time mousemove was called. Your move() function now only has to add this value to the x-coords.
Hope this helps you out somewhat

Resources