Pasting Sprites on a Drawing Canvas

0 favourites
  • 4 posts
From the Asset Store
Pixel Destruction like in "Worms" (Drawing Canvas based)
  • I am creating a hex based, static map by pasting hex shaped sprites on a very large drawing canvas. The hex shaped sprite has one animation with a number of different frames, each frame representing different terrain. Before pasting each sprite, I get the current terrain type from another object, change the current animation frame of the sprite to the correct number and then paste it to the canvas.

    Here is a simplified example code for pasting a column of hexes (instead of getting the correct frame from the world map, I simply calculate it from the current row):

    + System: For "CurrentRow" from 0 to RowsNeeded

    -> Hex: Set position to (CurrentColumnCenterX, LoopIndex("CurrentRow") × Self.Height + RowOffset)

    -> Hex: Set animation frame to LoopIndex % Hex.AnimationFrameCount

    -> HexMapCanvas: Paste object Hex without effects

    Everything works fine, except that all hexes in the map are the same. They all turn out the same way as the last hex of the last column. There is a warning on the Paste object action stating that: "If an object is destroyed the same tick that you paste it, it will not be drawn, since drawing happens at the end of the tick." I assume that this also is the reason for all pasted objects looking the same, and therefore this is the intended behaviour and not a bug. Is that correct? In that case I have a workaround for this.

  • MikaelS

    is there a reason why you want to paste the tiles to a canvas? You could just create all the sprites you need for the board. As long as collisions are turned off and the sprites don't have any behaviors or effects, they take up little memory or processing time...

    plus, then you can update a tile if it has "damage", or changes ownership, etc...

    I made a quick test, you can get it here:

    https://www.rieperts.com/games/forum/hextile.capx

  • AllanR

    Thanks a lot for the answer and the fantastic example. The reason that I was pasting the hexes to the canvas instead of using them directly was that I had imagined that having thousands of sprites as tiles would be a performance problem. However, this was not the case, and I am now using animated hexes for the map and still have 60 FPS.

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Making the hexs that are off screen invisible will also help.

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