GameZero.jl的Actor()方法无法使用指定的图像。

huangapple go评论95阅读模式
英文:

GameZero.jl Actor() method unable to use specified image

问题

When trying out GameZero.jl, the Actor() method is not finding the specified file location.

When entering something like:

ship = Actor("C:/path/to/images/image.png"; pos=(100, 100), angle=90)

or

ship = Actor("./images/image.png"; pos=(100, 100), angle=90)

I get the error:

ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] getproperty
   @ .\Base.jl:37 [inlined]
 [2] getindex
   @ .\refvalue.jl:56 [inlined]
 [3] file_path(name::String, subdir::Symbol)
   @ GameZero C:...\.julia\packages\GameZero\q74y7\src\resources.jl:46
 [4] image_surface(image::String)
   @ GameZero C:...\.julia\packages\GameZero\q74y7\src\resources.jl:37
 [5] Actor(image::String; kv::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:pos, :angle), Tuple{Tuple{Int64, Int64}, Int64}}})
   @ GameZero C:...\.julia\packages\GameZero\q74y7\src\actor.jl:18
 [6] top-level scope
   @ c:...\Documents\practice_gamezero\main.jl:59

Why can't it define an actor? I'm simply trying to run the wiki's example code with a placeholder image.

Edit:
I am simply trying to run the example project from the wiki:
https://docs.juliahub.com/GameZero/tTDGf/0.3.1/examples/Galaxian/

Edit After Solution:
Do not use a full or even relative path to your image. Making sure to organize the directory as directed, use something like:

ship = Actor("image.png"; pos=(100, 100), angle=90)

and make sure to call it all using rungame(path/to/main.jl), and not by running main.jl

英文:

When trying out GameZero.jl, the Actor() method is not finding the specified file location.

When entering something like:

ship = Actor("C:/path/to/images/image.png"; pos=(100, 100), angle=90)

or

ship = Actor("./images/image.png"; pos=(100, 100), angle=90)

I get the error:

ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] getproperty
   @ .\Base.jl:37 [inlined]
 [2] getindex
   @ .\refvalue.jl:56 [inlined]
 [3] file_path(name::String, subdir::Symbol)
   @ GameZero C:...\.julia\packages\GameZero\q74y7\src\resources.jl:46
 [4] image_surface(image::String)
   @ GameZero C:...\.julia\packages\GameZero\q74y7\src\resources.jl:37
 [5] Actor(image::String; kv::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol}, NamedTuple{(:pos, :angle), Tuple{Tuple{Int64, Int64}, Int64}}})
   @ GameZero C:...\.julia\packages\GameZero\q74y7\src\actor.jl:18
 [6] top-level scope
   @ c:...\Documents\practice_gamezero\main.jl:59

Why can't it define an actor? I'm simply trying to run the wiki's example code with a placeholder image.


Edit:
I am simply trying to run the example project from the wiki:
https://docs.juliahub.com/GameZero/tTDGf/0.3.1/examples/Galaxian/

Edit After Solution:
Do not use a full or even relative path to your image. Making sure to organize the directory as directed, use something like:

ship = Actor("image.png"; pos=(100, 100), angle=90)

and make sure to call it all using rungame(path/to/main.jl), and not by running main.jl

答案1

得分: 1

问题是 Actor 仅接受图像文件的名称作为参数,而不是其完整路径。

由于它已经知道并期望文件位于游戏文件夹中的 images/ 子目录中,所需的参数只是文件的名称,带或不带扩展名。

因此调用应该是:

ship = Actor("image.png", pos=(100, 100), angle=90)
英文:

The issue is that Actor takes only the name of the image file as its argument, not its full path.

Since it already knows and expects the file to be in the images/ subdirectory in the game folder, the argument it needs is just the name of the file, with or without extension.

So the call should be:

ship = Actor("image.png"; pos=(100, 100), angle=90)

huangapple
  • 本文由 发表于 2023年6月1日 01:19:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76375926.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定