Force refresh

For developers using the Construct 2 Javascript SDK

Post » Tue Apr 10, 2012 7:43 pm

Hello,

for reasons that I do not understand, both the inject and the loadfromURL plugin do not work on the iPad until something makes sprite refresh.

To clarify:

1) Creating a non-transparent sprite bigger than the inject/load sprite on top of it then destroying it triggers the loading/injecting
2) Touching the sprite several time after 2-3 seconds loads/injects the new image

This leads me to think that the problem lies in the refreshing of the canvas but executing this command:

this.runtime.redraw = true;

doesn't change anything, do you guys can point me in the right direction?

Thank you

B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Wed Apr 11, 2012 12:58 am

That line is the correct way to make the canvas redraw. The whole canvas will be repainted the next tick if you set redraw to true like that.

Perhaps it doesn't work because the browser takes longer than one tick to load images. Most browsers work asynchronously these days so changing an image is actually just a request to begin loading the new image, which is finished possibly some time later. To really fix it, make sure the image's loaded event also sets the redraw flag.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Wed Apr 11, 2012 9:14 am

@Ashley

Apparently that is not the problem, even a blinking object on top doesn't work, it's a problem here:

this.imageObj.onload = (function (self) {

this never fires, not until i keep on touching the screen (not one not two,but two/three in rapid sequence) do you have any idea on why this happens? Apparently only on iPad this happens.

Thank you
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Wed Apr 11, 2012 2:52 pm

No idea, it may be a bug in Safari on iOS that it doesn't fire onload events properly. Sorry, I don't know for sure any better.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Wed Apr 11, 2012 3:05 pm

@Ashley after testing it looks like a bug of the simulator but I'm not completely sure.
B
29
S
9
G
6
Posts: 525
Reputation: 8,294

Post » Wed Apr 11, 2012 3:44 pm

Does it work when you move the sprite with two actions to another place and then back? Should force two redraws - I suppose.
B
14
S
6
G
5
Posts: 173
Reputation: 4,742

Post » Wed Apr 11, 2012 6:13 pm

FYI the 'Set web font' feature of Text doesn't have a true 'loaded' event, and can take a few seconds to load. So for that I just forced refreshes on a timer: every 100 ms for the next 1 second (in case it loads quickly), then every 1 second for the next 5 seconds after that (so if it does load in the next 5s it should update for it). If all else fails, that might work for you too.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests