Object Picking trouble

For questions about using Classic.

Post » Tue May 17, 2011 4:16 am

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.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Tue May 17, 2011 12:09 pm

Might want to post a cap, as what your wanting should be very doable.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Tue May 17, 2011 7:44 pm

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.

[code:3kg1stf0]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.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Tue May 17, 2011 7:52 pm

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.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Tue May 17, 2011 7:57 pm

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.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Tue May 17, 2011 8:35 pm

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.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Tue May 17, 2011 8:43 pm

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.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Tue May 17, 2011 8:59 pm

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.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Wed May 18, 2011 8:09 am

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!
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Wed May 18, 2011 11:16 am

Sounds like the hotspot is being changed because of the size difference.
You can set it manually using set pivot point.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests