How to dynamic load the image of sprite?

0 favourites
  • 7 posts
From the Asset Store
Elevate your games with our AI Chatbot Integration! Seamlessly connect your Construct 3 projects with GPT-4 for dynamic,
  • 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?

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > 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)