Changing actor image with each click.

mikelemikele Member Posts: 1
edited February 2012 in Working with GS (Mac)
Hello, I'm new to gamesalad. I want to be able to change my actor image each time I click on it, up to three images and it stays on the last image. For example:

image0
Click
image1
click
image2
click...
image2

Thank you for your time.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited February 2012
    There are a few ways you can achieve this. One way is to create an attribute for the actor called "ImageNumber" (an integer). Have a rule that says when touch is pressed AND self.ImageNumber<2, Change Attribute self.ImageNumber to self.ImageNumber+1. Add a behavior (without a rule) that does Change Attribute self.Image to (use the expression editor) "image"..ImageNumber. The two periods will concatenate the word "image" with the value of the attribute and give you "image0" "image1" "image2" etc.

    There are more sophisticated implementations of this on the forums... see below (thanks @mrglockling).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • mrglocklingmrglockling Member Posts: 258
    edited February 2012
    Never mind this..
  • mrglocklingmrglockling Member Posts: 258
    edited February 2012
    create a "image" integer attribute
    then in the actor that changes you make 1 rule saying when touch is pressed change attribute "(game.image+1)%4" < %4 changes the attribute # 1-4 repeatedly
    Then make 4 more rules saying when attribute = 1 change image and repeat this changing the (1) to whatever number you want. Hope that makes sense
  • mikelemikele Member Posts: 1
    edited February 2012
    "Add a behavior (without a rule) that does Change Attribute self.Image to (use the expression editor) "image"..ImageNumber. The two periods will concatenate the word "image" with the value of the attribute and give you "image0" "image1" "image2" etc."

    This is not working correctly. I display the text and my imageNumber attribute is working correctly and incrementing when I click, but the image is not displayed.

    There is something wrong with this:
    Change Attribute: self.Image To:"image".."imageNumber
    I also tried
    Change Attribute: self.Image To:"image".."self.imageNumber

    Thank you Mr. Glockling, your code works once I took out %4 because I did not need to rotate it. But I didn't like how I had to make more rules for it to work. But it got it done.
  • CloudsClouds Member Posts: 1,599
    edited February 2012
    @mikele

    Make sure your images are named 1, 2, 3, 4, 5 . . . etc . . . .and then simply do this:

    image

Sign In or Register to comment.