Post: Easy way to position Shaders/Text
12-31-2011, 06:39 PM #1
d7w7z
Bounty hunter
(adsbygoogle = window.adsbygoogle || []).push({}); I was making a menu and got annoyed by the fact I had to keep making the patch over and over trying to guess good X and Y values, So I made this function to move elements around the screen.

    
PosTest(D) {
switch(D) {
case "U":
self moveOverTime( .1 );
self.Moving[self.TestNum].y -= 5;
break;
case "D":
self moveOverTime( .1 );
self.Moving[self.TestNum].y += 5;
break;
case "L":
self moveOverTime( .1 );
self.Moving[self.TestNum].x -= 5;
break;
case "R":
self moveOverTime( .1 );
self.Moving[self.TestNum].x += 5;
break;
case "Re":
self iPrintln("x: " + self.Moving[self.TestNum].x);
self iPrintln("y: " + self.Moving[self.TestNum].y);
break;
case "Sw":
self.TestNum++; if(self.TestNum > self.Moving.size) { self.TestNum =0; }
self iPrintln("Editing " + self.TestNum);
break;
} }

LoopRun( function, event, input) {
for(;Winky Winky {
self waittill( event );
self thread [[function]]( input );
} }



Make a function like this and add all the items you want to be able to move(shaders and text both work) to self.Moving. Don't forget to change "dpad_XXXX" to whatever controls your menu uses.
    
MenuDebug() {
self.Moving=[]; self.TestNum=0;
self.Moving[0]=self.scrollbar1;
self.Moving[1]=self.BackGroundHud;

self thread LoopRun( ::PosTest, "dpad_right", "R"); //Move Right
self thread LoopRun( ::PosTest, "dpad_left", "L"); //Move left
self thread LoopRun( ::PosTest, "dpad_up", "U" ); //Move Up
self thread LoopRun( ::PosTest, "dpad_down", "D"); //Move Down
self thread LoopRun( ::PosTest, "button_cross", "Re"); //Print X and Y values of current element
self thread LoopRun( ::PosTest, "button_square", "Sw"); //Switch to next element in self.Moving
}


Once you fine a good spot, print the X and Y then put the values as the X and Y for your element.
I might also add a way to scale the item up/down later...
(adsbygoogle = window.adsbygoogle || []).push({});

The following 2 users say thank you to d7w7z for this useful post:

Cmd-X, x_DaftVader_x
01-01-2012, 10:58 PM #11
Correy
I'm the Original
Originally posted by d7w7z View Post
Hitting a door with a sledge hammer also works for getting through it, Doesn't mean you should do it.


um, and whats that got to do with it :confused:
01-01-2012, 11:07 PM #12
d7w7z
Bounty hunter
Originally posted by Correy View Post
um, and whats that got to do with it :confused:

Just because your code works doesn't mean its a good idea to use your code is what I was trying to say.
01-03-2012, 01:33 AM #13
Blackstorm
Veni. Vidi. Vici.
Originally posted by d7w7z View Post
Serious?

Super lag because no wait in function, probly will crash the game. setText would crash the game before you got anything useful done if the lag didn't.



We found out setText isn't the problem, it's setting unique strings. :b
01-03-2012, 01:47 AM #14
Cmd-X
It's been awhile.
Originally posted by d7w7z View Post
I was making a menu and got annoyed by the fact I had to keep making the patch over and over trying to guess good X and Y values, So I made this function to move elements around the screen.

    
PosTest(D) {
switch(D) {
case "U":
self moveOverTime( .1 );
self.Moving[self.TestNum].y -= 5;
break;
case "D":
self moveOverTime( .1 );
self.Moving[self.TestNum].y += 5;
break;
case "L":
self moveOverTime( .1 );
self.Moving[self.TestNum].x -= 5;
break;
case "R":
self moveOverTime( .1 );
self.Moving[self.TestNum].x += 5;
break;
case "Re":
self iPrintln("x: " + self.Moving[self.TestNum].x);
self iPrintln("y: " + self.Moving[self.TestNum].y);
break;
case "Sw":
self.TestNum++; if(self.TestNum > self.Moving.size) { self.TestNum =0; }
self iPrintln("Editing " + self.TestNum);
break;
} }

LoopRun( function, event, input) {
for(;Winky Winky {
self waittill( event );
self thread [[function]]( input );
} }



Make a function like this and add all the items you want to be able to move(shaders and text both work) to self.Moving. Don't forget to change "dpad_XXXX" to whatever controls your menu uses.
    
MenuDebug() {
self.Moving=[]; self.TestNum=0;
self.Moving[0]=self.scrollbar1;
self.Moving[1]=self.BackGroundHud;

self thread LoopRun( ::PosTest, "dpad_right", "R"); //Move Right
self thread LoopRun( ::PosTest, "dpad_left", "L"); //Move left
self thread LoopRun( ::PosTest, "dpad_up", "U" ); //Move Up
self thread LoopRun( ::PosTest, "dpad_down", "D"); //Move Down
self thread LoopRun( ::PosTest, "button_cross", "Re"); //Print X and Y values of current element
self thread LoopRun( ::PosTest, "button_square", "Sw"); //Switch to next element in self.Moving
}


Once you fine a good spot, print the X and Y then put the values as the X and Y for your element.
I might also add a way to scale the item up/down later...


Wait would this work?
    
PosTest(D) {
switch(D) {
case "U":
self moveOverTime( .1 );
self.Moving[self.TestNum].y -= 5;
break;
case "D":
self moveOverTime( .1 );
self.Moving[self.TestNum].y += 5;
break;
case "L":
self moveOverTime( .1 );
self.Moving[self.TestNum].x -= 5;
break;
case "R":
self moveOverTime( .1 );
self.Moving[self.TestNum].x += 5;
break;
case "Re":
self iPrintln("x: " + self.Moving[self.TestNum].x);
self iPrintln("y: " + self.Moving[self.TestNum].y);
break;
case "Sw":
self.TestNum++; if(self.TestNum > self.Moving.size) { self.TestNum =0; }
self iPrintln("Editing " + self.TestNum);
break;
} }

LoopRun( function, event, input) {
for(;Winky Winky {
self waittill( event );
self thread [[function]]( input );
} }


    
MenuDebug() {
self.Moving=[]; self.TestNum=0;
self.Moving[0]=self.scrollbar1;
self.Moving[1]=self.BackGroundHud;

self thread LoopRun( ::PosTest, "dpad_right", "R");
self thread LoopRun( ::PosTest, "dpad_left", "L");
self thread LoopRun( ::PosTest, "dpad_up", "U" );
self thread LoopRun( ::PosTest, "dpad_down", "D");
self thread LoopRun( ::PosTest, "button_cross", "Re");
self thread LoopRun( ::PosTest, "button_square", "Sw");
}
01-03-2012, 04:23 AM #15
d7w7z
Bounty hunter
Originally posted by Blackstorm View Post
We found out setText isn't the problem, it's setting unique strings. :b

I already know that. His function was using setText to display the X and Y, Thats a unique string everytime its called. I used println instead.

---------- Post added at 04:23 AM ---------- Previous post was at 04:10 AM ----------

Originally posted by darkcarnival View Post
Wait would this work?
    
PosTest(D) {
switch(D) {
case "U":
self moveOverTime( .1 );
self.Moving[self.TestNum].y -= 5;
break;
case "D":
self moveOverTime( .1 );
self.Moving[self.TestNum].y += 5;
break;
case "L":
self moveOverTime( .1 );
self.Moving[self.TestNum].x -= 5;
break;
case "R":
self moveOverTime( .1 );
self.Moving[self.TestNum].x += 5;
break;
case "Re":
self iPrintln("x: " + self.Moving[self.TestNum].x);
self iPrintln("y: " + self.Moving[self.TestNum].y);
break;
case "Sw":
self.TestNum++; if(self.TestNum > self.Moving.size) { self.TestNum =0; }
self iPrintln("Editing " + self.TestNum);
break;
} }

LoopRun( function, event, input) {
for(;Winky Winky {
self waittill( event );
self thread [[function]]( input );
} }


    
MenuDebug() {
self.Moving=[]; self.TestNum=0;
self.Moving[0]=self.scrollbar1;
self.Moving[1]=self.BackGroundHud;

self thread LoopRun( ::PosTest, "dpad_right", "R");
self thread LoopRun( ::PosTest, "dpad_left", "L");
self thread LoopRun( ::PosTest, "dpad_up", "U" );
self thread LoopRun( ::PosTest, "dpad_down", "D");
self thread LoopRun( ::PosTest, "button_cross", "Re");
self thread LoopRun( ::PosTest, "button_square", "Sw");
}


The functions work fine. I haved used them to make a menu already.All you need to do is add the elements you want to move to self.Moving.

    
self.Moving[self.Moving.size]=self.Yourelement;


Then change the "dpad_right" "dpad_left"... ect to whatever notify's your menu uses.
01-03-2012, 04:23 AM #16
Blackstorm
Veni. Vidi. Vici.
Originally posted by d7w7z View Post
I already know that. His function was using setText to display the X and Y, Thats a unique string everytime its called. I used println instead.



Ohhhhhhhhhhhhh I see
01-03-2012, 04:45 AM #17
Correy
I'm the Original
Originally posted by Blackstorm View Post
Ohhhhhhhhhhhhh I see


you only use this as a one function anyway. i wouldnt put this into my menu, id use this to create my menu..
not like i never get the co-ords correct in the first place Winky Winky
01-03-2012, 05:40 AM #18
d7w7z
Bounty hunter
Originally posted by reScript
Every language and every script reads the same way, finish something then move to the next command or statement, this would not crash or lag.

Anything to do with unique strings is ir******** to your argument, unless you change your statements.


Correct, but you're forgetting that the game in running hundreds of threads at once, if one never stops taking up large amounts of processing power then the others lag, such as the animations, timers and movement functions.

I was talking about setText because it is a function which runs other threads and changes variables ect. He was saying he was setting only 2 variables per loop, this is not correct.

He edited his post to add a wait into the for loop because he knows I was right. End of story.
01-03-2012, 06:41 AM #19
d7w7z
Bounty hunter
Originally posted by reScript
There you explained it correct there. =D
One tiny script to add on to them hundred would not crash the game though. :p

Also quote from you "It would do the loop a few thousand times per second. Each loop would set 2 variables, check if a 2 buttons are pressed or not and call the setText function. No lag at all. :P", you said it only sets two variables aswell :/


He meant that the loop only set 2 variables then ended and went to the start of the loop. I meant he set 2, then called other functions which did checks and set variables.

You are also forgetting the game is straining the system already, prove in Mw3 ps3 which has lag spikes and is laggy in general. The other loop threads run 60 times per second (60 fps is max on consoles) if they are do not end after doing something. if there was 100 threads running this would be 6000 loops per second just from the game. His loop would of ran thousands of times per second just for one thread/function, that generates a lot of lag. Just because something is simple doesn't mean it can't use a lot of processing power.

The crash would be because he is using setText to display XY values of the element which is a unique string everytime you move the element which would crash the game very fast.

Moral of story, Always add a wait to a loop that never ends by its self.

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo