Object Picking trouble

This forum is currently in read-only mode.
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • So I have a container with a few objects. I create a few sets of these using a loop and Create object to create one of the objects, which creates them all. So far so good. One of the objects is a sprite. I set the position of the sprite immediately after creation in the loop, which works correctly, and each sprite is set to the correct position. However, when I set the frame of the sprite, every loop iteration seems to overwrite the frames for ALL the sprites. I'm not doing any object picking checks since I set position and frame as I create each sprite. It works for position( and size, and other properties etc) but apparently not for loading frames. When I load a frame in one sprite it works, but if then do load frame in another sprite, it replaces the frame of BOTH of the sprites.

  • Might want to post a cap, as what your wanting should be very doable.

  • Alright, I'll post a cap as soon as I get home. I suppose there could be something I'm missing but all I'm literally doing is:

    Container with textbox, sprite, an da couple of other things.

    For 1 to N, 
        Create Object Textbox
        Set position Textbox to SomeExpression + LoopIndex
        Set Text Textbox to SomeOtherExpression + LoopIndex
        Set position Sprite to YetAnotherExpression + LoopIndex
        Load animation frame from file Sprite to YetAnotherExpression2 + LoopIndex[/code:3kg1stf0]
    
    All of the lines seem to work fine except load animation frame from file, which does work except all the sprites end up being set to the last animation frame, instead of each sprite to its own.  I've tried, for example, looping through only some number N-x instead of looping to N, and the N-x file loads on all the sprites if I do that.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • When you load a frame with the sprite object it changes the frame of all the instances of the sprite because they all share the same image. It may be helpful to use the TiledBackground object since it can have a different image per instance.

  • Ah yes I see, I figured it was something like this. Is there some object that supports animation? I can't tell if the tiled background object does. If not, I could presumably pre-create all the sprites as separate entities, there's only about 100 of them.

  • You can add animation frames to sprite, and then change the instances frame to loopindex.

    But keep in mind it will be like having all 100 images contained in one sprite with multiple instances. If the images are small, and power of 2 then the vram shouldn't be an issue, but processing be be affected if there are many instances.

    Rojo's way is probably better in terms of performance.

  • Since they have ot be animated, 100 sprites by 5 or so frames each, I wonder if that might be an issue. Probably not since they're fairly small, but I think if there's no object with independent animation frames per instance, and if there's no way to create a new object (as opposed to an instance) at run-time then I might as well sit there and make copy-paste 100 sprites.

  • If your loading every frame, and not reusing anything then, yeah there probably will be some issues. Five hundred frames.....

    Might check and see how much the folder containing the frames takes up in disk space.

  • Alright I was able to fix this by making individual sprites. I have another issue now though. When I use Load animation frame from file with teh sprites to load a frame during run time, it move the sprite position. The movement varies by the image size of the image I try to load (or so it seems). Even when I load a frame that is the same size as the sprite object (32 x 32 .png files), the sprite still moves to a different (but predictable) location. I could convert all frames to the same size and then move them all by the same amount, no problem, but I was wondering if there was some way to prevent this from happening in the first place. Thanks!

  • Sounds like the hotspot is being changed because of the size difference.

    You can set it manually using set pivot point.

  • Well right, it seems to be changed due to loading, not just size difference (e.g. loading same-size frames as the sprite still moves it). Set current animation pivot sets the hotspot then? Great, thanks!

  • Ah, apparently the size of the sprite on the layout and the size of the sprite in the editor were not the same, which I guess might have been causing the issues as well.

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