faiface / pixel

A hand-crafted 2D game library in Go
MIT License
4.46k stars 245 forks source link

No error but window doesnt show #241

Closed frostways closed 4 years ago

frostways commented 4 years ago

Hi, I'm trying to build a game, I'm completely new to this... and I don't know how to structure a code... I've those tree codes This one which juste defines window :

package auxiliaire 

import (
    "github.com/faiface/pixel"
    "github.com/faiface/pixel/pixelgl"
)

//Config des fenêtres
var Dimension pixel.Rect = pixel.R(0, 0, 1400, 780) //dimenseion

var MainWindowCfg = pixelgl.WindowConfig{
    Bounds:    Dimension,
    Resizable: true,
    VSync:     true,
    Title:     "IACATS",
}

var MainWindow, _ = pixelgl.NewWindow(MainWindowCfg)
var Centre pixel.Vec = MainWindow.Bounds().Center()

This one which (in the future) run a level :

package niveaux

import (
    "jeu/auxiliaire"

    _ "github.com/faiface/pixel"
    _ "github.com/faiface/pixel/pixelgl"
    "golang.org/x/image/colornames"
)

func LaunchLvTest() {
    WindowLvTest := auxiliaire.MainWindow
    backgroundColor := colornames.Cornflowerblue
    for !WindowLvTest.Closed() {
        WindowLvTest.Clear(backgroundColor)
        WindowLvTest.Update()
    }
}

and the last one which is main :

package main

import (
    "jeu/niveaux"

    _ "github.com/faiface/pixel"
    "github.com/faiface/pixel/pixelgl"
)

func run() {
    niveaux.LaunchLvTest()
}

func main() {
    pixelgl.Run(run)
}

but it doesn't show any window just printing this in the terminal

(base) MBPdeAlexandre:jeu frostways$ go run main.go 
niveaux/niveautest.go:4:2: found packages auxiliaire (animations.go) and main (fenetres.go) in /Users/frostways/go/src/jeu/auxiliaire
delp commented 4 years ago

I suspect this has something to do with the way you are setting up your packages. Can you show your golang env variables like $GOPATH, $GOROOT, $GO111MODULE and the paths that those files are in please?

frostways commented 4 years ago

I suspect this has something to do with the way you are setting up your packages. Can you show your golang env variables like $GOPATH, $GOROOT, $GO111MODULE and the paths that those files are in please?

It was just a misunderstanding of how go packages are working. Ty fort you time <3

delp commented 4 years ago

Glad to hear you solved your problem, thanks for using Pixel

frostways commented 4 years ago

Glad to hear you solved your problem, thanks for using Pixel

Yeah I'm really enjoying this library but since I'm kinda new to programming and because there is not a lot of learning ressources about pixel (and I don't know the "regular" ways to code a game) It's quite hard but I enjoy the journey by now! Fortunately I'm studying math and physics at university... It helps for modelisation understanding and having ideas :')