0 Favourites

How to dynamic load the image of sprite?

  • I use construct 2 to create my first Html5 game.And I have a request that random to load image.For example,I have 5 images in my image folder,but every time user enter the game ,it just need to load one.

    So I create a sprite object first and I want when the page loading the sprite can random to set a image by global variable.How can I do?Or any methods?Thank you.

  • yes, just like you did,

    first step, create a new sprite object load images from your file and named.

    secondly, create a global variable, on the start of layout, set this variable to random(sprite.animationFrameCount+1)

    last, set sprite frame to variable.

  • yes, just like you did,

    first step, create a new sprite object load images from your file and named.

    secondly, create a global variable, on the start of layout, set this variable to random(sprite.animationFrameCount+1)

    last, set sprite frame to variable.

    Thank you so much.One question,I want to know how to set sprite frame to variable?Do you mean use the sprite event "load image from url"?Or any other way?

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • I use construct 2 to create my first Html5 game.And I have a request that random to load image.For example,I have 5 images in my image folder,but every time user enter the game ,it just need to load one.

    So I create a sprite object first and I want when the page loading the sprite can random to set a image by global variable.How can I do?Or any methods?Thank you.

    if you have the images inside a sprite, use the following

    on start of layout - sprite.setframe=round(random(self.animationframecount))

    see if that helps. keep in mind, using the animation frame count and a random of that total number, might be that some times, on start of layout you might get the same frame to show, since has no actual order.

  • > yes, just like you did,

    > first step, create a new sprite object load images from your file and named.

    > secondly, create a global variable, on the start of layout, set this variable to random(sprite.animationFrameCount+1)

    > last, set sprite frame to variable.

    >

    Thank you so much.One question,I want to know how to set sprite frame to variable?Do you mean use the sprite event "load image from url"?Or any other way?

    ... i mean when you create a sprite object, import frames from your file and choose all your images, then set the event that "on the start of layout -- action: set sprite frame to int(random(sprite.framecount+1))"

  • > I use construct 2 to create my first Html5 game.And I have a request that random to load image.For example,I have 5 images in my image folder,but every time user enter the game ,it just need to load one.

    > So I create a sprite object first and I want when the page loading the sprite can random to set a image by global variable.How can I do?Or any methods?Thank you.

    >

    if you have the images inside a sprite, use the following

    on start of layout - sprite.setframe=round(random(self.animationframecount))

    see if that helps. keep in mind, using the animation frame count and a random of that total number, might be that some times, on start of layout you might get the same frame to show, since has no actual order.

    Thank u ,it is fine.

  • >

    > > yes, just like you did,

    > > first step, create a new sprite object load images from your file and named.

    > > secondly, create a global variable, on the start of layout, set this variable to random(sprite.animationFrameCount+1)

    > > last, set sprite frame to variable.

    > >

    > Thank you so much.One question,I want to know how to set sprite frame to variable?Do you mean use the sprite event "load image from url"?Or any other way?

    >

    ... i mean when you create a sprite object, import frames from your file and choose all your images, then set the event that "on the start of layout -- action: set sprite frame to int(random(sprite.framecount+1))"

    Thank u so much.It is work

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)