www.webdeveloper.com
Results 1 to 5 of 5

Thread: Simple syntax query

Hybrid View

  1. #1
    Join Date
    Sep 2010
    Posts
    3

    Simple syntax query

    Hi there Gurus!

    Just a quick noob problem, could anyone please tell me how I need to imput these array values?

    Arrays:
    var houseRef = new Array();
    houseRef['L1a'] = new Array (250,100,350,700);
    houseRef['L1b'] = new Array (600,100,350,700);
    houseRef['L1c'] = new Array (950,100,350,700);

    Using array values:
    Goal:
    context.drawImage(img, 250, 100, 350, 700, 0, 0, 200, 400);

    This works:
    context.drawImage(img, houseRef['L1a'][0],houseRef['L1a'][1],houseRef['L1a'][2],houseRef['L1a'][3], 0, 0, 200, 400);

    This doesnt:
    context.drawImage(img, houseRef['L1a'], 0, 0, 200, 400);

    Thanks for your help in advance!

  2. #2
    Join Date
    May 2003
    Location
    Between Baltimore and DC
    Posts
    3,579
    You have to do it the way it works. The other way is just setting the 2nd parameter to an array. It will not break an array out to 4 arguments.

    Eric

  3. #3
    Join Date
    Sep 2010
    Posts
    3
    Awesome, thats really good to know Eric!

    One other query then, can you see a way to accomplish with a less code intensive method? Like a series of numeric variables rather than an array?

    Not too sure what the options are when youre wanting to use a series of numbers like this.

    Thanks again!

  4. #4
    Join Date
    May 2003
    Location
    Between Baltimore and DC
    Posts
    3,579
    Code:
    for(var ind in houseRef){
        var pnt = houseRef[ind];
        context.drawImage(img, pnt[0], pnt[1], pnt[2], pnt[3], 0, 0, 200, 400);
    }

  5. #5
    Join Date
    Sep 2010
    Posts
    3
    And again, thanks heaps Eric!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles