7 Replies - 1963 Views - Last Post: 19 February 2016 - 10:09 AM

#1 retched   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 25-January 16

"Invisible" input

Posted 18 February 2016 - 12:50 PM

I'm not sure if there is a better way to describe this, and it's really hard to describe...

I'm noticing on a few Flash games that I have they allow for a user to input something off-screen, and then with a push of a button causes that to work load on the main stage...

My question is how is this done? Is there some kind of invisible field that the coders are using or is it something akin to building a string together and then sending it to another handler for that string on keypress.

[Forgot I can't edit posts...]

So the idea I wanted to do is this... On a flash stage, I wanted to use a deck of playing cards. BUT not at random. I wanted to call up on particular card and have it displayed. But aside from loading 52 images or movie clips on to the main stage, my questions is how do I call them in. I was thinking of something like using "QD" for Queen of Diamonds... But not sure how I should go ahead and invoke this. Do I use 52 images... or 52 Movie Clips.

Is This A Good Question/Topic? 0
  • +

Replies To: "Invisible" input

#2 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2365
  • View blog
  • Posts: 7,219
  • Joined: 15-January 14

Re: "Invisible" input

Posted 18 February 2016 - 02:01 PM

You should have a library object for a card, where you can customize each instance (the suit, value, background image, etc). The library object would contain the code and other things that apply to all cards. You can just create those in memory with code, you can write code to create a new instance of a library object and just not add it to the stage yet. As far as capturing input, if you have a keypress handler on the main stage then you can use that to record a buffer of what keys they press and check the buffer to see if they're typing in a certain string you support.
Was This Post Helpful? 0
  • +
  • -

#3 retched   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 25-January 16

Re: "Invisible" input

Posted 18 February 2016 - 03:53 PM

So instead of including the 52 objects, you're suggesting I draw each of the 52 cards individually?

And by the buffer? I assume that would be what I suggested with the string variable and just appending it right?
Was This Post Helpful? 0
  • +
  • -

#4 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2365
  • View blog
  • Posts: 7,219
  • Joined: 15-January 14

Re: "Invisible" input

Posted 18 February 2016 - 04:30 PM

Your library would have 1 movie clip for a card, and 52 pictures (if you want a picture on each card). When you create each card in Actionscript you create an instance of the card movie clip symbol and pass it the things that make it unique. There's a description about things like this that starts here:

http://help.adobe.co...8ea63-7fee.html

So you could do something like this to create the deck (I haven't tested this and it's been a while since I used Actionscript, so it probably doesn't work but hopefully you get the idea):

var suits:Array = ['spades', 'hearts', 'diamonds', 'clubs'];
var vals:Array = ['A', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K'];
var deck:Array = [];
var i:Number = 0, j:Number = 0;
var card:Card;

for (i = 0; i < suits.length; i++) {
  for (j = 0; j < vals.length; j++) {
    card = new Card(suits[i], vals[j]); // create a new card for each suit and value
    deck.push(card);
  }
}


Now you have a deck of all cards. The constructor for the Card class gets the suit and value, and you could combine those to get the image, for example (e.g., spadesA, spades7, etc) to pull out of the library and put on the card instance. The cards wouldn't be visible on the stage until you added them to something already being displayed.

Quote

And by the buffer? I assume that would be what I suggested with the string variable and just appending it right?

Yeah, you could use a string or an array. Traditionally a buffer is more like an array with a maximum length. If the maximum length is 100 then each time they press a key you would use Array.unshift to add the character to the beginning of the array. If the array is then longer than 100 then you use Array.pop to remove the last element. So the array would be the last 100 characters that the pressed. If you used a string that you kept adding letters to but never shortened then that's a memory leak that would eventually use up all of their memory storing everything they ever pressed.
Was This Post Helpful? 1
  • +
  • -

#5 retched   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 25-January 16

Re: "Invisible" input

Posted 18 February 2016 - 05:40 PM

View PostArtificialSoldier, on 18 February 2016 - 06:30 PM, said:

Yeah, you could use a string or an array. Traditionally a buffer is more like an array with a maximum length. If the maximum length is 100 then each time they press a key you would use Array.unshift to add the character to the beginning of the array. If the array is then longer than 100 then you use Array.pop to remove the last element. So the array would be the last 100 characters that the pressed. If you used a string that you kept adding letters to but never shortened then that's a memory leak that would eventually use up all of their memory storing everything they ever pressed.


Ah ha! I figured that might be a problem doing it the string way. I kind of thought a conditional like this might work (and I know this will probably be a problem to code):

If Either C, D, H, S is pressed:
strCard = LetterPressed
End If

If Number 1-0 or K, Q, J pressed Then
strCard &= KeyPressed
EndIf

If UpArrow pressed Then
RetrieveCard(strCard)
strCard = ""
EndIf

Does that one make sense?
Was This Post Helpful? 0
  • +
  • -

#6 retched   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 25-January 16

Re: "Invisible" input

Posted 18 February 2016 - 07:42 PM

Actually looking at this... in hindsight, arrays are probably better.
Was This Post Helpful? 0
  • +
  • -

#7 retched   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 25-January 16

Re: "Invisible" input

Posted 19 February 2016 - 12:27 AM

Okay so I did a bit of work on this... here's the coding I got so far...

			// If any key 0-9, K, Q, J is pressed... add to the FIRST slot of the array.
			if (((event.charCode >= 48 && event.charCode <= 57) || event.keyCode == Keyboard.K || event.keyCode == Keyboard.Q || event.keyCode == Keyboard.J) && inputLock == false) {
				userinput[1] = String.fromCharCode(event.charCode).toUpperCase();
				trace("A key was pressed.... it was the " + String.fromCharCode(event.charCode).toUpperCase() + " key. I put it in the Rank Slot.");
			}
			
			if (((event.keyCode == Keyboard.C) || (event.keyCode == Keyboard.D) || (event.keyCode == Keyboard.H) || (event.keyCode == Keyboard.S)) && inputLock == false) {
				userinput[0] = String.fromCharCode(event.charCode).toUpperCase();
				trace("A key was pressed.... it was the " + String.fromCharCode(event.charCode).toUpperCase() + " key. I put it in the Suit Slot.");
			}
			
			// Press the UP Arrow to load the card into the displayer and to block anymore changes from being made...
			if (event.keyCode == Keyboard.UP && userinput[0] != null && userinput[1] != null) {
				
				inputLock = true;
				
				trace("Hey! We have the card! It's actually... Suit: " + userinput[0] + " Rank: " + userinput[1]);
				
				
			}
			
			// Press the DOWN ARROW to clear the displayer and to clear/unlock the Card Input
			if (event.keyCode == Keyboard.DOWN) {
				
				userinput[0] = null;
				userinput[1] = null;	
				
				inputLock = false;
				
				trace("Awww... We had a card, and now we cleared it... The card and rank are empty.");
			}
			
			// If the LEFT ARROW is pressed.... move the card from the middle to the left and clear/unlock the card input.
			if (event.keyCode == Keyboard.LEFT && userinput[0] != null && userinput[1] != null) { // Only do this if the key input is NOT empty.
				
				inputLock = false;
				userinput[0] = null;
				userinput[1] = null;	
				
				trace("Awww... We had a card, and now we cleared it... The card and rank are empty.");
				trace("We also moved a card onto the LEFT player's table. The card count is now: " + t1CardCount_int.toString);
				
			}



Now the problem that I'm having is what do I do to actually pull the image from the library to be displayed when the appropriate UP/DOWN button is displayed. I started to load symbols and images name C2 for 2 of Clubs and the like. But now I don't exactly see what do I do make it appear in a certain holder.
Was This Post Helpful? 0
  • +
  • -

#8 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2365
  • View blog
  • Posts: 7,219
  • Joined: 15-January 14

Re: "Invisible" input

Posted 19 February 2016 - 10:09 AM

That's part of what I was talking about in post 4. You need to create a movie clip in the library and give it a symbol name, like Card, which will be the class name for Actionscript. You'll need to create a class for it like in the Adobe documentation. The code that goes in the class will include all of the code that applies to all cards, like display or animation code or things like that. When you create the card with the given suit and rank then the class can use that information to pull in an image from the library to use on that card instance. You could have a placeholder image in the card class where you put the image from the library. There's an example of doing that here:

http://www.codingcol...om-the-library/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1