prances Posted October 20, 2014 Share Posted October 20, 2014 Hi, I am trying to to use the code from an example for dragging sprites to let me count the number of times a sprite has been clicked. I want to place sprites on the screen that will serve as buttons that will tell the stage to addChild new Sprites. I have been able to place a button and cause that button being pressed to generate one new sprite, but now I want to generate more exactly like it. And I am not sure how to do this. Also, I am not sure if placing the logic to create a new sprite inside the mousedown function curly braces is the best way to be creating the first sprite to begin with. See my code snippet below for an example. addResistor.mousedown = addResistor.touchstart = function(data){ // stop the default event... data.originalEvent.preventDefault(); // store a reference to the data // The reason for this is because of multitouch // we want to track the movement of this particular touch this.data = data; this.alpha = 0.9; this.dragging = true; stage.addChild(resistor); }; addResistor is the sprite that serves as the button and resistor is the sprite that gets added. I had thought of using a counter variable declared outside the curly braces and passed in, but this doesn't seem to work. I am open to creating a slightly different resistor each time by addChilding one labeled R1 for the first push, and R2 for the second push if creating duplicate Sprites is not possible/ too difficult. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.