Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8308047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:40:50+00:00 2026-06-08T18:40:50+00:00

I have an array of sprites: for (i = 0; i < 3; i++)

  • 0

I have an array of sprites:

for (i = 0; i < 3; i++) {
    var newLine:Sprite = new Sprite();
    newLine.graphics.beginFill(0xFFFFFF); 
    newLine.graphics.drawRect((uiSizeX * (.25 + .25 * i)) + (doorSizeX - lineLengths[0][i]) / 2, uiSizeY * .5, lineLengths[0][i], lineHeight); 
    newLine.name = "lines" + i;
    lines.push(newLine);
}

I later add each to a background Sprite:

for (i = 0; i < 3; i++) {
    uiContainer.addChild(doors[i]);
    uiContainer.addChild(lines[i]);
}

And later wish to change the width of the rectangles contained in each. When I set the width property using the array reference:

lines[i].width = lineLengths[trialNumber][i];

The rectangle moves towards the center of the stage and uiContainer. Trying to set the x value results in even stranger behavior. I’ve gathered from answers to other questions that this is because the sprite is empty, which is confusing since it seems like it should have a rectangle in it. How do I access or change the properties of the rectangle or make it so the sprite is not empty?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:40:53+00:00Added an answer on June 8, 2026 at 6:40 pm

    Never try to directly change the width or height of a sprite, unless you really really have to, because it leads to all sorts of unexpected behavior.

    If you want to resize the sprite, then redraw the rectangle:

    var sprite = lines[i];
    
    sprite.graphics.beginFill(0xFFFFFF); 
    sprite.graphics.drawRect(newWidth, newHeight);
    

    Also don’t forget to call endFill:

    sprite.graphics.endFill();
    

    You should probably wrap all this logic into a separate class so that you can redraw your sprites more easily. Even better, create a class that extends Sprite and that contains all the logic to redraw/resize.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of sprites called segments and I would like to skip
Say we have array of arrays: tree_limbs = Array.new tree_limbs << %w(1 2 3
I have a mutable array which stores sprites but the problem is that the
If I have a sprite in a NSMutableArray of sprites in Cocos2d and need
We are talking 2D sprites here, so I have 4 vertices for each sprite
I have an array of sprites and run an action on each element. the
I have an NSMutable array that I want to add Sprites to so that
I have 10 picture on scene as sprites.And they are in an array.The pictures(sprites)
I have array INPUTFILES with n files INPUTFILES=( file_0 ... files_n-1 ) And i
I have array of hashes: @array = [{:id => 1, :status=>R}, {:id => 1,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.