Loading image from the internet.

Get help using Construct 2

Post » Thu Feb 13, 2014 7:05 pm

This feature of the sprite object doesn't seem to work at all!
I need to have an image loaded from a URL and displayed in my application, however i cannot get this to work properly with the default sprite object.

Here's what i'm trying to do:
Keyboard | On Space pressed --- sprite | Load image from "http://gamemakerblog.com/wp-content/uploads/2011/02/construct-2-logo.png" (Resize to image size)

I even tried to add a text object which would show when the image is supposed to show, but this shows me that the event fired by pressing the space triggers, however the "On image URL loaded" never triggers. Testing in Chrome without WebGL, internet connection is fine.

The test image i use:


Nothing is displayed. What am i doing wrong?Stiivais2014-02-13 19:06:18
B
10
S
1
Posts: 163
Reputation: 1,436

Post » Thu Feb 13, 2014 7:08 pm

Update (and a shameless bump), the console of the chrome browser shows the following:
Cross-origin image load denied by Cross-Origin Resource Sharing policy.
B
10
S
1
Posts: 163
Reputation: 1,436

Post » Thu Feb 13, 2014 7:10 pm

I think the problem is with permissionsof the server, some website let you do that, others don't, the manual says:

Load image from URL
Load an image from a given URL. The current animation frame will be replaced with the image. It is not shown until the image has finished downloading, and On image URL loaded triggers. Images loaded from different domains are subject to the same cross-domain restrictions as AJAX requests - for more information see the section on cross-domain in the AJAX object. Data URIs can also be passed as an image, e.g. from a canvas snapshot or webcam image. The Size parameter sets whether the Sprite object will be set to the image size when it loads, or whether to keep its current size and stretch the image.


and so the part about cross domain request here counts: https://www.scirra.com/manual/107/ajax

EDIT:Ninja'd by the OP,that was weirdAphrodite2014-02-13 19:11:02
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Post » Thu Feb 13, 2014 7:13 pm

@Aphrodite I already checked the manual, but i've also tried about 4 or 5 different images including ones from Photobucket, which supposedly allow cross-requesting. A google search turned up a StackOverflow page, in which people claim that this is a bug with chrome... >_>

Edit: However, images can easily be loaded from a base64 string. Any idea how i could convert an image to such a string somewhere online and then just retrieve the string to be loaded?

also, ninja'dStiivais2014-02-13 19:15:29
B
10
S
1
Posts: 163
Reputation: 1,436

Post » Thu Feb 13, 2014 7:21 pm

It works perfectly in Node-Webkit (and probably other browsers). It appears that i might have to switch browsers (assuming that this is isolated to chrome). >_>

Update: It appears that it indeed might have been have a problem with the host, as images from dropbox load just fine. But why did the Webkit work, then?Stiivais2014-02-13 19:35:24
B
10
S
1
Posts: 163
Reputation: 1,436

Post » Thu Feb 13, 2014 7:46 pm

[QUOTE=Stiivais] It works perfectly in Node-Webkit (and probably other browsers). It appears that i might have to switch browsers (assuming that this is isolated to chrome). >_>

Update: It appears that it indeed might have been have a problem with the host, as images from dropbox load just fine. But why did the Webkit work, then?[/QUOTE]

One theory (I can be wrong) could be that Node Webkit applications don't suffer from the same restriction, as the C2 manual stated that browser manufacturers havechosen to do this (for security reasons)
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
54
S
22
G
18
Posts: 2,123
Reputation: 17,150

Post » Thu Feb 13, 2014 8:46 pm

*sigh*
I am now considering making something in CC that would parse the content of such sites. Either way, i guess i'll just stick to the dropbox for now.
B
10
S
1
Posts: 163
Reputation: 1,436


Return to How do I....?

Who is online

Users browsing this forum: dop2000, Yahoo [Bot] and 32 guests