Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DarkSlash · Sep 13, 2013 at 07:07 PM · arrayarrays

Show an image array in a loop

Think in a slot machine.

In one column, I got an array of X images ("Slide", in the image below, has 3 elements as example). I got a window (a GUILayout). I want that the images of the array are shown in that window, then the image moves down, and the next image of the array moves in the window. I got that. The thing is that when I reach the end of the array, there're no more images to show. I need to put back the 1st element of the array on the top of the last image. How can I do that??

I leave an image for better explanation.

alt text

Code: Here the array has 13 elements. Only can be shown 3 elements at time (it's a 3x5 slot machine, the image was illustrative, to get the idea).

 function drawCol(col : int, movement :float)
 {
     var x : int = 0 + (col * images[0].width);
     var y : float = 0;
     var image : Texture2D;
             
     GUILayout.BeginArea(Rect(slotX, slotY, images[0].width * 5, images[0].height * 3));
     
     for(var i : int = 0; i < 13; i++) 
     {            
         if(oneTime == false) 
         { 
             // Fills the array with random symbols
             
             var randomImage : int = Random.Range(0,images.length);
             image = images[randomImage]; 
             slotGrid[col,i] = randomImage;
         }
         else     
         {                    
             image = images[slotGrid[col,i]];  //Gets the already stored symbols
         }    
         
         // Sets y based on the height of the image (uses 0 index because all images must have the same size)
         // rests images[0].height * 10 because if not, the slot grid is drawn from 0 to 1536. We need that is
         // drawn from -1536 to 384 (slot grid area, where the Layout is)
         
         y = images[0].height * i + movement - (images[0].height * 10);
                         
         if((y < images[0].height * 3) && (y  >= slotY - images[0].height )) // Only draws a texture if it's in visible area 
         {
             GUI.DrawTexture(Rect(x, y, image.width, image.height), image);
         }
     }    
     
     GUILayout.EndArea();
 }
explanation.jpg (68.3 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gardian06 · Sep 13, 2013 at 07:33 PM 0
Share
  • how do you track what your current position in the array is?

  • do you only maintain a current?

  • or do you maintain a next, and a previous?

avatar image DarkSlash · Sep 13, 2013 at 07:43 PM 0
Share

I don't track, I just got t he y position. I have the whole array. I just display the elements that are in the window. Im posting the source code for a better understanding!

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Seizure · Sep 13, 2013 at 07:32 PM

If I'm reading this correctly it sounds like you need a temp array, I would suggest using this temp array as the display array, once you reach the end of the listArray start filling the temp array with listArray 1; I'll work on a script real quick and see if it helps you.

EDIT: Hope code works for you.

 using UnityEngine;
 using System.Collections;
 
 public class arrayDisplay : MonoBehaviour {
     
     public int[] displayHolder;
     public int[] tempArray;
     public int counter;
 
     // Use this for initialization
     void Start () {
         
         for (int i = 0; i < 3; i++)
         {
             tempArray[i] = displayHolder[i];  //Initialize tempArray    
         }
         StartCoroutine(arrayDisplayer());
     
     }
     
     IEnumerator arrayDisplayer ()
     {
         Debug.Log ("tempArray" + tempArray[0]);
         Debug.Log ("tempArray" + tempArray[1]);
         Debug.Log ("tempArray" + tempArray[2]);
         yield return new WaitForSeconds (1);
         
         if (counter >= 9)
             counter = 0;
         else
             counter++;
         tempArray[0] = displayHolder[counter];  //Initialize tempArray    
         if (counter >= 9)
             counter = 0;
         else
             counter++;
         tempArray[1] = displayHolder[counter];  //Initialize tempArray    
         if (counter >= 9)
             counter = 0;
         else
             counter++;
         tempArray[2] = displayHolder[counter];  //Initialize tempArray    
 
         StartCoroutine(arrayDisplayer());
     }
 }
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DarkSlash · Sep 13, 2013 at 07:42 PM 0
Share

thanks! I will try that!

avatar image DarkSlash · Sep 14, 2013 at 07:13 PM 0
Share

Thanks for taking the time to code that! I tried but, as Im displaying the images of the array in a smooth movement, I can't use that, because it switchs the position from 9 to 0 in an instant.

But I took your advice of using and temp array! So I created a 3x1 temp array. When the last image of the regular array appears in the screen, I just put the temp array above y that image. When the last regular array image moves down, also does the 3 temp array images. When the last temp array image shows in the screen (that means that the regular array images are all out of the screen) I reset the timer, so the regular array images moves on top of the temp array images!

Thanks!! :)

avatar image DarkSlash · Sep 15, 2013 at 02:57 AM 0
Share

Following your advice, I got this, but the draw calls are much more than excepted... 40 at the begging (ins$$anonymous$$d of the 15 expected) and 100 in the switch between the temp array and the regular array! If I move just one column, the draw calls peak doesn't affect the performance (I still get 58 fps) but if I uncomment the lines and I roll the 5 columns, the draw calls peak leaves me with a 5 fps performance!! I checked the draw calls and still get that stat... any idea?? This is my code: https://dl.dropboxusercontent.com/u/7059378/code.js

avatar image DarkSlash · Sep 18, 2013 at 12:32 AM 0
Share

I put the code in this question, just for the drawcall, because the way of showing the image array is solved :)

http://answers.unity3d.com/questions/538011/too-many-drawtexture-calls.html

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How Do I Add An Instantiated Object To An Array? 3 Answers

How to Clone Array1 into Array2 in Unity? Using JavaScript. 0 Answers

My array does not update when object is destroyed. How do I fix it? (java) 2 Answers

How do I use array's to spawn gameobjects(C#)? 3 Answers

Copy Array to a Stack 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges