Changing image in the prefered order? A challenge.
I have a mini game for my game where I was thinking of having objects bounce around on the screen and the user will have to press the objects, the objects then change image to a number. Starting from 1 to 5. It´s easy to set up a rule to change image, but I need to have it this way : The first object that is pressed will have to show the image of the number 1, then the number 2, then the number 3 etc. Does this make any sense? :P
Comments
…use tables
in actorPrototype add attribute … index type … named myRow
set it to numbers 1 thru 5 on each actor instance in scene
create table TB-images … 5 rows : 1 column
in the column … text type … type in names of the number images (exactly as they are in your import … but you do not need to add the .png)
on actorPrototype:
-changeAttribute: self.Image To: tableCellValue(select TB-images,select myRow, 1)
(this sets the first image to display)
Rule: when
Attribute: self.myRow > 5
-changeAttribute: self.myRow To: 0
Rule: when
Event: touch is pressed
-changeAttribute: self.myRow To: self.myRow+1
-changeAttribute: self.Image To: tableCellValue(select TB-images,select myRow, 1)
(when you want them to continue after one touch … use a Timer with Run to completion)
**another way**
name your instances of onePrototype: 1 thru 5
-changeAttribute: self.Image To: self.Name
Rule: when
Event: touch is pressed
-changeAttribute: self.Tags To: do
Rule: when
Attribute: self.Tags is do
-Rule: when
-Attribute: self.Name is 1
-Animate (drag in image 2; 3; 4; 5; 1) : √ Loop
-Otherwise:
--Rule: when
--Attribute: self.Name is 2
--Animate (drag in image 3; 4; 5; 1 ;2) : √ Loop
--Otherwise: for 3, and 4; and 5
**and of course you could use Timers**
Every: 1 second
-changeAttribute: self.Image To self.Image+1
Rule: when
Attribute: self.Image = 5
Timer: After: 1 second
-changeAttribute: self.image To: 1
@};- MH
http://img4.imageshack.us/img4/1795/20120809101409pm.png
http://img19.imageshack.us/img19/6732/20120809101334pm.png
http://img256.imageshack.us/img256/2376/20120809101316pm.png
http://img442.imageshack.us/img442/7713/20120809101240pm.png
Thanks for your help.
one 'myRow' attribute on the Prototype (not 5)
on the 5 actorInstances change that attribute from 0 to a number: 1 or 2 or 3 or 4 or 5
table looks great … (didn't actually need but always good to know how to do!)
rules/behaviors look good
but please title/name/comment them in their titleBar:
Rule: touchPressed > myRowChange; imageChange
Rule: myRow = 5 > reset to 1
that will remind you what you want to do and make problem finding easier
think if you delete the extra 'myRow' … things should work super!
Either way, wouldn't it be easiest to have an attribute self.clickCount (index) and increase it with each Touch is Pressed? And then have a few rules that say When self.clickCount = 1 --> Change Image [image #1]; When self.clickCount = 2 --> Change Image [image #2], etc.? And then if you want all actors to work that way, use a game-level attribute instead of an actor-level attribute.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@tatiang : I have 5 footballs on the screen. When the player press any one of the balls I want it to change image of the number 1, when the secound ball is pressed I want it to change to a image of the number 2 etc. It is important that an image of the number 2 don´t show the first time a ball is pressed or the number 1 the last time. It has to be in the order of 1 to 5. A tool to help children to count. Make any sense? :P
Hi @nypraise The method @tatiang suggested will work fine for you then, except make the ClickCount attribute a game integer attribute. To add more detail:
In your football 1 actor: When touch is pressed and game.ClickCount = 0
Change Image
Change Attribute game.ClickCount to 1
In your football 2 actor: When touch is pressed and game.ClickCount = 1
Change Image
Change Attribute game.ClickCount to 2
etc.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
If the image is pressed and the countClick is 0 it shows the image 1 and change the attribute to of countClick to 1.
Otherwise is the image is pressed and the countClick is 1, it will show the image of number 2 and change the attribute to 2 etc.
And just have 5 balls with the same rules.
I would think this would solve the problem, but what happens is when I press the actor/ball in the preview is that it shows image 1 for 0.001 sec and jumps right to image 2. For me it seems like it don´t understand the "otherwise" command. Couse it should not change to the image of 2 unless the countClick is 1.
Any thoughts?
on numberActor:
add attribute … boolean … named done
Rule: when
Event: touch is pressed
Attribute: self.done is false
-changeAttribute: clickCount To: clickCount+1 (before image changes)
-changeAttribute: self.Image To: clickCount
-changeAttribute: self.done To: true
clickCount default is 0
then changes to 1 … which is the name of the image you want
then changes self.Image To: the # in clickCount … which is 1
the next numberActor touched will first change the clickCount To: 2
then changes self.Image To: 2
I did it right?
What is the purpose of this Done attribute? I don´t get it.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
(a) When the player clicks on a ball, only that ball changes its number. So if all of the balls have a 1 on them and the player clicks a ball, that ball changes to 2 and every other ball is still 1.
(b) When the player clicks on a ball, every ball changes its number. So if all of the balls have a 1 on them and the player clicks a ball, all of the balls are now 2.
edit: (c) Wait, I think I'm understanding better now. You want it so that when a player clicks the first ball, it changes to 1, and when a player clicks the second ball, that ball changes to 2. Aha!
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
[Attachment removed; see below]
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
The difference between a game attribute and an actor attribute is that a game attribute is a single attribute that any actor can reference, while an actor's attribute is only visible (normally) to that instance of the actor. So in this case, if game.clickCount increases (from 1 to 2), then all of the actors see game.clickCount as a higher number (2). But if you have different actors or multiple instances of an actor and self.clickCount increases (from 1 to 2) on an actor, the other actors don't have access to that attribute. Their own self.clickCount would remain at 1 (or whatever it was before).
When you want to make a new attribute, ask yourself if other actors need to know the value of that attribute. If so, make it a game-level attribute. If not, make it an actor-level (self.) attribute. Examples of these would be game.currentLevel, game.allEnemiesSpeed, self.position.X, etc.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User